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.='
| '; for($i=0;$i | Summary | '; $str.'|||||||
| '; for($i=0;$i<=count($days);$i++){ $str.=' | ![]() | ';
//$str.='>60 (h:m) | '; $str.='![]() | ';
}
$str.='|||||
| '.$r['first_name'].' '.$r['last_name'].' ('.$r['phone_work'].') | '; 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.=''.$vv[$ta].' '.$vv[$ta.'_distinct'].' '.$vv[$ta.'_new'].' | ';
else $str.='0 0 0 | ';
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.=''.$h.'h '.$m.'m | '; } else $str.='0h 0m | '; } $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.=''.$all[$k][$ta].' '.$all[$k][$ta."_distinct"].' '.$all[$k][$ta."_new"].' | ';
else $str.='0 0 0 | ';
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.=''.$h.'h '.$m.'m | '; } else $str.='0h 0m | '; } } $str.='
| Summary | '; 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.=''.$al[$ta].' '.$al[$ta."_distinct"].' '.$al[$ta."_new"].' | ';
else $str.='0 0 0 | ';
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.=''.$h.'h '.$m.'m | '; } else $str.='0h 0m | '; } } } foreach($type_arr as $ta){ if($ta=="answered_up_60")$sty="border-left: 1px solid #cccccc"; else $sty=""; if($allaa[$ta])$str.=''.$allaa[$ta].' '.$allaa[$ta."_distinct"].' '.$allaa[$ta."_new"].' | ';
else $str.='0 0 0 | ';
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.=''.$h.'h '.$m.'m | '; } else $str.='0h 0m | '; } $str.='