loadLanguage('MyEcmCallsMoreDashlets'); if(!empty($def['height'])) $this->height = $def['height']; $this->user = $def['user']; if($def['date'])$this->date = $GLOBALS['timedate']->to_display_date($def['date']); else $this->date=$GLOBALS['timedate']->to_display_date(date("Y-m-d")); if(count($this->user)==0){ $w=$GLOBALS['db']->query("select id from users where deleted='0' and status='Active' and phone_work!=''"); while($r=$GLOBALS['db']->fetchByAssoc($w)){ $this->user[]=$r['id']; } } parent::Dashlet($id); // call parent constructor $this->isConfigurable = true; // dashlet is configurable $this->hasScript = true; // dashlet has javascript attached to it // if no custom title, use default if(empty($def['title'])) $this->title = $this->dashletStrings['LBL_TITLE']; else $this->title = $def['title']; } function display() { $ss = new Sugar_Smarty(); $ss->assign('savedText', $this->savedText); $ss->assign('saving', $this->dashletStrings['LBL_SAVING']); $ss->assign('saved', $this->dashletStrings['LBL_SAVED']); $ss->assign('id', $this->id); $ss->assign('height', $this->height); $str=''; //echo $this->date; $exp=explode("-",$GLOBALS['timedate']->to_db_date($this->date)); //echo $GLOBALS['timedate']->to_db_date($this->date)."mm"; $dm=$exp[1]; $dd=$exp[2]; $dy=$exp[0]; $trd=array( 6=>0, 0=>1, 1=>2, 2=>3, 3=>4, 4=>5, 5=>6, ); //echo "
".$dy." ".$dm." ".$dd; $no_actual_day=date("w",mktime(0,0,0,$dm,$dd,$dy)); //echo $no_actual_day; $date_first=date("Y-m-d",mktime(0,0,0,$dm,$dd,$dy)-($no_actual_day)*(3600*24)+3600*24); //echo $date_first; $expl=explode("-",$date_first); $ds=array(0,1,2,3,4); $m=0; foreach($ds as $dss){ $days[$m]=date("Y-m-d",mktime(0,0,0,$expl[1],$expl[2],$expl[0])+$m*3600*24); $m++; } //print_r($days); /* $days[$no_actual_day]=$GLOBALS['timedate']->to_db_date($this->date); //echo $this->date;die(); if($no_actual_day>0){ for($i=0;$i<$no_actual_day;$i++){ $days[$i]=date("Y-m-d",mktime(0,0,0,$dm,$dd,$dy)-($i+1)*(3600*24)); } } for($i=$no_actual_day+1;$i<=6;$i++){ $days[$i]=date("Y-m-d",mktime(0,0,0,$dm,$dd,$dy)+($i-$no_actual_day)*(3600*24)); }*/ //$this->user=array("178770a9-cd31-9f5e-6ee4-4acb40f6381c","dbf183f4-70da-2e17-1745-4acb40d0294b"); if(count($this->user)>0){ foreach($this->user as $u){ foreach($days as $ddd){ $w=$GLOBALS['db']->query("select * from ecmcallsphones where bean_id='".$u."'"); while($r=$GLOBALS['db']->fetchByAssoc($w)){ /*$p[$r['bean_id'][$ddd]]['busy']=mysql_num_rows($GLOBALS['db']->query("select id from cdr where disposition='BUSY' and src='".$r['phone']."' and (calldate like '".$ddd."%')")); $ww=$GLOBALS['db']->query("select duration from cdr where disposition='BUSY' and src='".$r['phone']."' and (calldate like '".$ddd."%')"); while($rr=$GLOBALS['db']->fetchByAssoc($ww)){ $p[$r['bean_id']][$ddd]['busy_duration']+=$rr['duration']; }*/ $p[$r['bean_id']][$ddd]['answered_up_60']=mysql_num_rows($GLOBALS['db']->query("select id from cdr where disposition like 'ANSWERED' and deleted='0' and duration>60 and src='".$r['phone']."' and (calldate like '".$ddd."%')")); $ww=$GLOBALS['db']->query("select duration,dst from cdr where disposition='ANSWERED' and deleted='0' and duration>60 and src='".$r['phone']."' and (calldate like '".$ddd."%')"); $temp=array(); $dttt=0; while($rr=$GLOBALS['db']->fetchByAssoc($ww)){ $p[$r['bean_id']][$ddd]['answered_up_60_duration']+=$rr['duration']; $temp[$rr['dst']]+=$rr['duration']; } $p[$r['bean_id']][$ddd]['answered_up_60_distinct']=count($temp); foreach($temp as $tte)$dttt+=$tte; $p[$r['bean_id']][$ddd]['answered_up_60_distinct_duration']=$dttt; $temp_cnt=0; $dur_tt=0; if(count($temp)>0){ foreach($temp as $temp_key=>$temp_value){ $www=$GLOBALS['db']->query("select dst,duration from cdr where disposition='ANSWERED' and deleted='0' and duration>60 and src='".$r['phone']."' and dst='".$temp_key."' and calldate like '".$ddd."%'"); if(mysql_num_rows($GLOBALS['db']->query("select dst,duration from cdr where disposition='ANSWERED' and deleted='0' and duration>60 and src='".$r['phone']."' and dst='".$temp_key."' and calldate<'".$ddd."'"))==0){ $temp_cnt++; } while($rrr=$GLOBALS['db']->fetchByAssoc($www))$dur_tt+=$rrr['duration']; } } $p[$r['bean_id']][$ddd]['answered_up_60_new']=$temp_cnt; $p[$r['bean_id']][$ddd]['answered_up_60_new_duration']=$dur_tt; $p[$r['bean_id']][$ddd]['failed']=mysql_num_rows($GLOBALS['db']->query("select id from cdr where disposition like 'ANSWERED' and deleted='0' and duration<=60 and src='".$r['phone']."' and (calldate like '".$ddd."%')")); $ww=$GLOBALS['db']->query("select duration,dst from cdr where disposition like 'ANSWERED' and deleted='0' and duration<=60 and src='".$r['phone']."' and (calldate like '".$ddd."%')"); $temp=array(); $dttt=0; while($rr=$GLOBALS['db']->fetchByAssoc($ww)){ $p[$r['bean_id']][$ddd]['failed_duration']+=$rr['duration']; $temp[$rr['dst']]+=$rr['duration']; } $p[$r['bean_id']][$ddd]['failed_distinct']=count($temp); foreach($temp as $tte)$dttt+=$tte; $p[$r['bean_id']][$ddd]['failed_distinct_duration']=$dttt; $temp_cnt=0; $dur_tt=0; if(count($temp)>0){ foreach($temp as $temp_key=>$temp_value){ $www=$GLOBALS['db']->query("select dst,duration from cdr where disposition like 'ANSWERED' and deleted='0' and duration<=60 and src='".$r['phone']."' and dst='".$temp_key."' and calldate like '".$ddd."%'"); if(mysql_num_rows($GLOBALS['db']->query("select dst,duration from cdr where disposition like 'ANSWERED' and deleted='0' and duration<=60 and src='".$r['phone']."' and dst='".$temp_key."' and calldate<'".$ddd."'"))==0){ $temp_cnt++; } while($rrr=$GLOBALS['db']->fetchByAssoc($www))$dur_tt+=$rrr['duration']; } } $p[$r['bean_id']][$ddd]['failed_new']=$temp_cnt; $p[$r['bean_id']][$ddd]['failed_new_duration']=$dur_tt; /*echo '
';
					print_r($p[$r['bean_id']]);
					echo '
'; $p[$r['bean_id']][$ddd]['failed']=mysql_num_rows($GLOBALS['db']->query("select id from cdr where disposition='FAILED' and src='".$r['phone']."' and (calldate like '".$ddd."%')")); $ww=$GLOBALS['db']->query("select duration from cdr where disposition='FAILED' and src='".$r['phone']."' and (calldate like '".$ddd."%')"); while($rr=$GLOBALS['db']->fetchByAssoc($ww)){ $p[$r['bean_id']][$ddd]['failed_duration']+=$rr['duration']; } $p[$r['bean_id']][$ddd]['no_answer']=mysql_num_rows($GLOBALS['db']->query("select id from cdr where disposition='NO ANSWER' and src='".$r['phone']."' and (calldate like '".$ddd."%')")); $ww=$GLOBALS['db']->query("select duration from cdr where disposition='NO ANSWER' and src='".$r['phone']."' and (calldate like '".$ddd."%')"); while($rr=$GLOBALS['db']->fetchByAssoc($ww)){ $p[$r['bean_id']][$ddd]['no_answer_duration']+=$rr['duration']; }*/ } } } } $days=$this->multisort($days,array(array('key'=>0,'sort'=>'asc'))); //echo '
';
		//print_r($p);
		//echo '
'; $str.='
'; $str.=''; $str.=''; $str.=''; for($i=0;$ito_display_date($days[$i]).''; } $str.=''; $str.''; $str.=''; $str.=''; for($i=0;$i<=count($days);$i++){ $str.=''; //$str.=''; $str.=''; } $str.=''; $type_arr=array("answered_up_60","failed"); $type_arr_distinct=array("answered_up_60_distinct","failed_distinct"); if(count($p)>0){ foreach($p as $k=>$v){ $r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select first_name,last_name,phone_work from users where id='".$k."'")); if($k){ $str.=''; $str.=''; foreach($v as $kk=>$vv){ foreach($type_arr as $ta){ if($ta=="answered_up_60")$sty="border-left: 1px solid #cccccc"; else $sty=""; if($vv[$ta])$str.=''; else $str.=''; if($ta!="failed"){ if($vv[$ta.'_duration']){ $m=floor($vv[$ta.'_duration']/60); $h=floor($vv[$ta.'_duration']/3600); $m=$m-60*$h; $m2=floor($vv[$ta.'_distinct_duration']/60); $h2=floor($vv[$ta.'_distinct_duration']/3600); $m2=$m2-60*$h2; $m3=floor($vv[$ta.'_new_duration']/60); $h3=floor($vv[$ta.'_new_duration']/3600); $m3=$m3-60*$h3; $str.=''; } else $str.=''; } $all[$k][$ta]+=$vv[$ta]; $all[$k][$ta."_distinct"]+=$vv[$ta."_distinct"]; $all[$k][$ta."_new"]+=$vv[$ta."_new"]; if($ta!="failed")$all[$k][$ta.'_duration']+=$vv[$ta.'_duration']; if($ta!="failed")$all[$k][$ta.'_distinct_duration']+=$vv[$ta.'_distinct_duration']; if($ta!="failed")$all[$k][$ta.'_new_duration']+=$vv[$ta.'_new_duration']; $alla[$kk][$ta]+=$vv[$ta]; $alla[$kk][$ta."_distinct"]+=$vv[$ta."_distinct"]; $alla[$kk][$ta."_new"]+=$vv[$ta."_new"]; if($ta!="failed")$alla[$kk][$ta.'_duration']+=$vv[$ta.'_duration']; if($ta!="failed")$alla[$kk][$ta.'_distinct_duration']+=$vv[$ta.'_distinct_duration']; if($ta!="failed")$alla[$kk][$ta.'_new_duration']+=$vv[$ta.'_new_duration']; $allaa[$ta]+=$vv[$ta]; $allaa[$ta."_distinct"]+=$vv[$ta."_distinct"]; $allaa[$ta."_new"]+=$vv[$ta."_new"]; if($ta!="failed")$allaa[$ta.'_duration']+=$vv[$ta.'_duration']; if($ta!="failed")$allaa[$ta.'_distinct_duration']+=$vv[$ta.'_distinct_duration']; if($ta!="failed")$allaa[$ta.'_new_duration']+=$vv[$ta.'_new_duration']; } } foreach($type_arr as $ta){ if($ta=="answered_up_60")$sty="border-left: 1px solid #cccccc"; else $sty=""; if($all[$k][$ta])$str.=''; else $str.=''; if($ta!="failed"){ if($all[$k][$ta.'_duration']){ $m=floor($all[$k][$ta.'_duration']/60); $h=floor($all[$k][$ta.'_duration']/3600); $m=$m-60*$h; $m2=floor($all[$k][$ta.'_distinct_duration']/60); $h2=floor($all[$k][$ta.'_distinct_duration']/3600); $m2=$m2-60*$h2; $m3=floor($all[$k][$ta.'_new_duration']/60); $h3=floor($all[$k][$ta.'_new_duration']/3600); $m3=$m3-60*$h3; $str.=''; } else $str.=''; } } $str.=''; } } } $str.=''; if(count($alla)>0){ foreach($alla as $al){ foreach($type_arr as $ta){ if($ta=="answered_up_60")$sty="border-left: 1px solid #cccccc"; else $sty=""; if($al[$ta])$str.=''; else $str.=''; if($ta=="failed")continue; if($al[$ta.'_duration']){ $m=floor($al[$ta.'_duration']/60); $h=floor($al[$ta.'_duration']/3600); $m=$m-60*$h; $m2=floor($al[$ta.'_distinct_duration']/60); $h2=floor($al[$ta.'_distinct_duration']/3600); $m2=$m2-60*$h2; $m3=floor($al[$ta.'_new_duration']/60); $h3=floor($al[$ta.'_new_duration']/3600); $m3=$m3-60*$h3; $str.=''; } else $str.=''; } } } foreach($type_arr as $ta){ if($ta=="answered_up_60")$sty="border-left: 1px solid #cccccc"; else $sty=""; if($allaa[$ta])$str.=''; else $str.=''; if($ta=="failed")continue; if($allaa[$ta.'_duration']){ $m=floor($allaa[$ta.'_duration']/60); $h=floor($allaa[$ta.'_duration']/3600); $m=$m-60*$h; $m2=floor($allaa[$ta.'_distinct_duration']/60); $h2=floor($allaa[$ta.'_distinct_duration']/3600); $m2=$m2-60*$h2; $m3=floor($allaa[$ta.'_new_duration']/60); $h3=floor($allaa[$ta.'_new_duration']/3600); $m3=$m3-60*$h3; $str.=''; } else $str.=''; } $str.=''; $str.='
 Summary
 >60 (h:m)
'.$r['first_name'].' '.$r['last_name'].' ('.$r['phone_work'].')'.$vv[$ta].'
'.$vv[$ta.'_distinct'].'
'.$vv[$ta.'_new'].'
0
0
0
'.$h.'h '.$m.'m0h 0m'.$all[$k][$ta].'
'.$all[$k][$ta."_distinct"].'
'.$all[$k][$ta."_new"].'
0
0
0
'.$h.'h '.$m.'m0h 0m
Summary'.$al[$ta].'
'.$al[$ta."_distinct"].'
'.$al[$ta."_new"].'
0
0
0
'.$h.'h '.$m.'m0h 0m'.$allaa[$ta].'
'.$allaa[$ta."_distinct"].'
'.$allaa[$ta."_new"].'
0
0
0
'.$h.'h '.$m.'m0h 0m
'; $str.='
'; return parent::display("") . $str . '
'; // return parent::display for title and such } /** * Displays the javascript for the dashlet * * @return string javascript to use with this dashlet */ function multisort($data,$keys) { if(count($data)>0) { foreach($data as $key => $row) { foreach($keys as $k) { $cols[$k['key']][$key] = $row[$k['key']]; } } $idkeys=@array_keys($data); $i=0; foreach($keys as $k) { if($i>0)$sort.=','; $sort.='$cols['.$k['key'].']'; if($k['sort'])$sort.=',SORT_'.strtoupper($k['sort']); if($k['type'])$sort.=',SORT_'.strtoupper($k['type']); $i++; } $sort.=',$idkeys'; $sort='@array_multisort('.$sort.');'; eval($sort); foreach($idkeys as $idkey) { $result[$idkey]=$data[$idkey]; } return $result; } } function displayScript() { $ss = new Sugar_Smarty(); $ss->assign('saving', $this->dashletStrings['LBL_SAVING']); $ss->assign('saved', $this->dashletStrings['LBL_SAVED']); $ss->assign('id', $this->id); $str = $ss->fetch('modules/Home/Dashlets/MyEcmCallsMoreDashlets/MyEcmCallsMoreDashletsScript.tpl'); return $str; // return parent::display for title and such } /** * Displays the configuration form for the dashlet * * @return string html to display form */ function displayOptions() { global $app_strings; $ss = new Sugar_Smarty(); $ua=''; $w=$GLOBALS['db']->query("select first_name,last_name,id from users where deleted='0' and status='Active' and phone_work!='' order by user_name asc"); while($r=$GLOBALS['db']->fetchByAssoc($w)) { $ua.=''; } $ss->assign('user_options', $ua); $ss->assign('date', $this->date); $ss->assign('titleLbl', $this->dashletStrings['LBL_CONFIGURE_TITLE']); $ss->assign('statusLbl', $this->dashletStrings['LBL_CONFIGURE_STATUS']); $ss->assign('userLbl', $this->dashletStrings['LBL_CONFIGURE_USER']); $ss->assign('typeLbl', $this->dashletStrings['LBL_CONFIGURE_TYPE']); $ss->assign('saveLbl', $app_strings['LBL_SAVE_BUTTON_LABEL']); $ss->assign('title', $this->title); $ss->assign('height', $this->height); $arr=array("d","m","Y","y"); $arrp=array("%d","%m","%Y","%y"); $ss->assign('format', str_replace($arr,$arrp,$GLOBALS['timedate']->get_date_format())); $ss->assign('id', $this->id); return parent::displayOptions() . $ss->fetch('modules/Home/Dashlets/MyEcmCallsMoreDashlets/MyEcmCallsMoreDashleOptions.tpl'); } function saveOptions($req) { global $sugar_config, $timedate, $current_user, $theme; $options = array(); $options['title'] = $_REQUEST['title']; $options['user'] = $_REQUEST['user']; $exp=explode("-",$GLOBALS['timedate']->to_db_date($_REQUEST['date'])); $options['date'] = date("Y-m-d",mktime(0,0,0,$exp[1],$exp[2],$exp[0])+3600*24); if(is_numeric($_REQUEST['height'])) { if($_REQUEST['height'] > 0 && $_REQUEST['height'] <= 300) $options['height'] = $_REQUEST['height']; elseif($_REQUEST['height'] > 300) $options['height'] = '300'; else $options['height'] = '100'; } return $options; } } ?>