[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Calendar/ -> Appointment.php (source)

   1  <?php
   2  /*********************************************************************************
   3  ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9  *
  10   ********************************************************************************/
  11  require_once ('modules/Calendar/CalendarCommon.php');
  12  require_once ('include/utils/CommonUtils.php');
  13  require_once ('include/utils/UserInfoUtil.php');
  14  require_once ('include/database/PearDatabase.php');
  15  require_once ('modules/Calendar/Activity.php');
  16  class Appointment
  17  {
  18      var $start_time;
  19      var $end_time;
  20      var $subject;
  21      var $participant;
  22      var $participant_state;
  23      var $contact_name;
  24      var $account_id;
  25      var $account_name;
  26      var $creatorid;
  27      var $creator;
  28      var $owner;
  29      var $ownerid;
  30      var $assignedto;
  31      var $eventstatus;
  32      var $priority;
  33      var $activity_type;
  34      var $description;
  35      var $record;
  36      var $temphour;
  37      var $tempmin;
  38      var $image_name;
  39      var $formatted_datetime;
  40      var $duration_min;
  41      var $duration_hour;
  42      var $shared = false;
  43      var $recurring;
  44      var $dur_hour;
  45  
  46  	function Appointment()
  47      {
  48          $this->participant = Array();
  49          $this->participant_state = Array();
  50          $this->description = "";
  51      }
  52      
  53      /** To get the events of the specified user and shared events
  54        * @param $userid -- The user Id:: Type integer
  55            * @param $from_datetime -- The start date Obj :: Type Array
  56            * @param $to_datetime -- The end date Obj :: Type Array
  57            * @param $view -- The calendar view :: Type String
  58        * @returns $list :: Type Array
  59       */
  60      
  61  	function readAppointment($userid, &$from_datetime, &$to_datetime, $view)
  62      {
  63          global $current_user,$adb;
  64          require('user_privileges/user_privileges_'.$current_user->id.'.php');
  65          require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
  66          $and = "AND (
  67                      (
  68                          (
  69                              (CAST(CONCAT(date_start,' ',time_start) AS DATETIME) >= ? AND CAST(CONCAT(date_start,' ',time_start) AS DATETIME) <= ?)
  70                              OR	(CAST(CONCAT(due_date,' ',time_end) AS DATETIME) >= ? AND CAST(CONCAT(due_date,' ',time_end) AS DATETIME) <= ? )
  71                              OR	(CAST(CONCAT(date_start,' ',time_start) AS DATETIME) <= ? AND CAST(CONCAT(due_date,' ',time_end) AS DATETIME) >= ?)
  72                          )
  73                          AND vtiger_recurringevents.activityid is NULL
  74                      )
  75                  OR (
  76                          (CAST(CONCAT(vtiger_recurringevents.recurringdate,' ',time_start) AS DATETIME) >= ?
  77                              AND CAST(CONCAT(vtiger_recurringevents.recurringdate,' ',time_start) AS DATETIME) <= ?)
  78                          OR	(CAST(CONCAT(due_date,' ',time_end) AS DATETIME) >= ? AND CAST(CONCAT(due_date,' ',time_end) AS DATETIME) <= ?)
  79                          OR	(CAST(CONCAT(vtiger_recurringevents.recurringdate,' ',time_start) AS DATETIME) <= ?
  80                              AND CAST(CONCAT(due_date,' ',time_end) AS DATETIME) >= ?)
  81                      )
  82                  )";
  83          
  84          $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=>
  85                              'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
  86          
  87              $q= "select vtiger_activity.*, vtiger_crmentity.*,
  88                      case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name
  89                      FROM vtiger_activity
  90                          inner join vtiger_crmentity on vtiger_activity.activityid = vtiger_crmentity.crmid
  91                          left join vtiger_recurringevents on vtiger_activity.activityid=vtiger_recurringevents.activityid
  92                          left join vtiger_groups on vtiger_groups.groupid = vtiger_crmentity.smownerid
  93                          LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid
  94                      WHERE vtiger_crmentity.deleted = 0 and vtiger_activity.activitytype not in ('Emails','Task') $and ";
  95  
  96          // User Select Customization: Changes should made also in (calendayLaout getEventList) and one more BELOW
  97          $query_filter_prefix = calendarview_getSelectedUserFilterQuerySuffix(); 
  98          $q .= $query_filter_prefix; 
  99          // END
 100          $h = $from_datetime->z_hour;
 101          $m = $from_datetime->min;
 102          if(empty($m)) {
 103              $m = '00';
 104          }
 105          $startDate = new DateTimeField($from_datetime->year."-".$from_datetime->z_month."-".
 106                  $from_datetime->z_day." $h:$m");
 107          $h = '23';
 108          $m = '59';
 109          $endDate = new DateTimeField($to_datetime->year."-".$to_datetime->z_month."-".
 110                  $to_datetime->z_day." $h:$m");
 111          $params = array(
 112              $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue(),
 113              $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue(),
 114              $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue(),
 115              $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue(),
 116              $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue(),
 117              $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue()
 118          );
 119          if($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[16] == 3)
 120          {
 121              //Added for User Based Custom View for Calendar
 122              $sec_parameter=getCalendarViewSecurityParameter();
 123              $q .= $sec_parameter;
 124          }
 125                                      
 126          $q .= " AND vtiger_recurringevents.activityid is NULL ";
 127          $q .= " group by vtiger_activity.activityid ORDER by vtiger_activity.date_start,vtiger_activity.time_start";
 128  
 129          $r = $adb->pquery($q, $params);
 130          $n = $adb->getRowCount($r);
 131          $a = 0;
 132          $list = Array();
 133          
 134          while ( $a < $n )
 135          {
 136              
 137              $result = $adb->fetchByAssoc($r);
 138              $from = strtotime($result['date_start']);
 139              $to = strtotime($result['due_date']. ' '. $result["time_end"]);
 140              $windowTo = strtotime($endDate->getDBInsertDateTimeValue());
 141              for($j = $from; $j <= $to; $j=$j+(60*60*24))
 142              {
 143  
 144                  $obj = &new Appointment();
 145                  $temp_start = date("Y-m-d",$j);
 146                  $endTime = strtotime($temp_start. ' '.  $result['time_start']);
 147                  if($endTime > $windowTo) {
 148                      break;
 149                  }
 150              
 151                  $result["date_start"]= $temp_start ;
 152                  list($obj->temphour,$obj->tempmin) = explode(":",$result["time_start"]);
 153                  if($start_timestamp != $end_timestamp && $view == 'day'){
 154                      if($j == $start_timestamp){
 155                          $result["duration_hours"] = 24 - $obj->temphour;
 156                      }elseif($j > $start_timestamp && $j < $end_timestamp){
 157                          list($obj->temphour,$obj->tempmin)= $current_user->start_hour !=''?explode(":",$current_user->start_hour):explode(":","08:00");
 158                          $result["duration_hours"] = 24 - $obj->temphour;
 159                      }elseif($j == $end_timestamp){
 160                          list($obj->temphour,$obj->tempmin)= $current_user->start_hour !=''?explode(":",$current_user->start_hour):explode(":","08:00");
 161                          list($ehr,$emin) = explode(":",$result["time_end"]);
 162                          $result["duration_hours"] = $ehr - $obj->temphour;
 163                      }
 164                  }
 165                  $obj->readResult($result, $view);
 166                  $list[] = $obj;
 167                  unset($obj);
 168  
 169              }
 170              $a++;
 171              
 172          }
 173          //Get Recurring events
 174          $q = "SELECT vtiger_activity.*, vtiger_crmentity.*, case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name , vtiger_recurringevents.recurringid, vtiger_recurringevents.recurringdate as date_start ,vtiger_recurringevents.recurringtype,vtiger_groups.groupname from vtiger_activity inner join vtiger_crmentity on vtiger_activity.activityid = vtiger_crmentity.crmid inner join vtiger_recurringevents on vtiger_activity.activityid=vtiger_recurringevents.activityid left join vtiger_groups on vtiger_groups.groupid = vtiger_crmentity.smownerid LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid";
 175          $q .= getNonAdminAccessControlQuery('Calendar',$current_user);
 176          $q.=" where vtiger_crmentity.deleted = 0 and vtiger_activity.activitytype not in ('Emails','Task') AND (cast(concat(recurringdate, ' ', time_start) as datetime) between ? and ?) ";
 177          
 178          // User Select Customization
 179          $q .= $query_filter_prefix;
 180          // END
 181  
 182          $params = array($startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue());
 183                                                      
 184          $q .= " ORDER by vtiger_recurringevents.recurringid";
 185          $r = $adb->pquery($q, $params);
 186          $n = $adb->getRowCount($r);
 187          $a = 0;
 188          while ( $a < $n )
 189                  {
 190              $obj = &new Appointment();
 191                          $result = $adb->fetchByAssoc($r);
 192              list($obj->temphour,$obj->tempmin) = explode(":",$result["time_start"]);
 193                          $obj->readResult($result,$view);
 194                          $a++;
 195              $list[] = $obj;
 196                          unset($obj);
 197                  }
 198  
 199  
 200          usort($list,'compare');
 201          return $list;
 202      }
 203  
 204  
 205      /** To read and set the events value in Appointment Obj
 206            * @param $act_array -- The vtiger_activity array :: Type Array
 207            * @param $view -- The calendar view :: Type String
 208           */
 209  	function readResult($act_array, $view)
 210      {
 211          global $adb,$current_user,$app_strings;
 212          $format_sthour='';
 213                  $format_stmin='';
 214          $this->description       = $act_array["description"];
 215          $this->eventstatus       = getRoleBasesdPickList('eventstatus',$act_array["eventstatus"]);
 216          $this->priority         = getRoleBasesdPickList('taskpriority',$act_array["priority"]);
 217          $this->subject           = $act_array["subject"];
 218          $this->activity_type     = $act_array["activitytype"];
 219          $this->duration_hour     = $act_array["duration_hours"];
 220          $this->duration_minute   = $act_array["duration_minutes"];
 221          $this->creatorid         = $act_array["smcreatorid"];
 222          //$this->creator           = getUserName($act_array["smcreatorid"]);
 223          $this->assignedto = $act_array["user_name"];
 224                  $this->owner   = $act_array["user_name"];
 225          if(!is_admin($current_user))
 226          {
 227              if($act_array["smownerid"]!=0 && $act_array["smownerid"] != $current_user->id && $act_array["visibility"] == "Public"){
 228                  $que = "select * from vtiger_sharedcalendar where sharedid=? and userid=?";
 229                  $row = $adb->pquery($que, array($current_user->id, $act_array["smownerid"]));
 230                  $no = $adb->getRowCount($row);
 231                  if($no > 0)
 232                      $this->shared = true;
 233              }
 234          }    
 235          $this->image_name = $act_array["activitytype"].".gif";
 236          if(!empty($act_array["recurringid"]) && !empty($act_array["recurringtype"]))
 237              $this->recurring="Recurring.gif";
 238          
 239          $this->record            = $act_array["activityid"];
 240          $date = new DateTimeField($act_array["date_start"].' '. $act_array['time_start']);
 241          $eventStartDate = DateTimeField::convertToDBFormat($date->getDisplayDate());
 242          list($eventStartHour) = explode(':', $date->getDisplayTime());
 243          list($styear,$stmonth,$stday) = explode("-",$act_array["date_start"]);
 244          list($sthour, $stmin) = explode(':', $act_array['time_start']);
 245          if($act_array["notime"] != 1){
 246              $st_hour = $eventStartHour;
 247          }else{
 248              $st_hour = 'notime';
 249              $act_array["time_start"] = "00:00";
 250          }
 251          list($eyear,$emonth,$eday) = explode("-",$act_array["due_date"]);
 252          list($end_hour,$end_min) = explode(":",$act_array['time_end']);
 253  
 254          $start_date_arr = Array(
 255              'min'   => $stmin,
 256              'hour'  => $sthour,
 257              'day'   => $stday,
 258              'month' => $stmonth,
 259              'year'  => $styear
 260          );
 261          $end_date_arr = Array(
 262              'min'   => $end_min,
 263              'hour'  => $end_hour,
 264              'day'   => $eday,
 265              'month' => $emonth,
 266              'year'  => $eyear
 267          );
 268                  $this->start_time        = new vt_DateTime($start_date_arr,true);
 269                  $this->end_time          = new vt_DateTime($end_date_arr,true);
 270          if($view == 'day' || $view == 'week')
 271          {
 272              $this->formatted_datetime= DateTimeField::convertToUserFormat($eventStartDate)
 273                      .":".$st_hour;
 274          }
 275          elseif($view == 'year')
 276          {
 277              list($year,$month,$date) = explode("-",$eventStartDate);
 278              $this->formatted_datetime = $month;
 279          }
 280          else
 281          {
 282              $this->formatted_datetime= DateTimeField::convertToUserFormat($eventStartDate);
 283          }
 284          return;
 285      }
 286      
 287      
 288  }
 289  
 290  /** To two array values
 291    * @param $a -- The vtiger_activity array :: Type Array
 292    * @param $b -- The vtiger_activity array :: Type Array
 293    * @returns value 0 or 1 or -1 depends on comparision result
 294   */
 295  function compare($a,$b)
 296  {
 297      if ($a->start_time->ts == $b->start_time->ts)
 298      {
 299          return 0;
 300         }
 301      return ($a->start_time->ts < $b->start_time->ts) ? -1 : 1;
 302  }
 303  function getRoleBasesdPickList($fldname,$exist_val)
 304  {
 305      global $adb,$app_strings,$current_user;
 306      $is_Admin = $current_user->is_admin;
 307          if($is_Admin == 'off' && $fldname != '')
 308              {
 309                  $roleid=$current_user->roleid;
 310                  $roleids = Array();
 311                  $subrole = getRoleSubordinates($roleid);
 312                  if(count($subrole)> 0)
 313                  $roleids = $subrole;
 314                  array_push($roleids, $roleid);
 315  
 316                  //here we are checking wheather the table contains the sortorder column .If  sortorder is present in the main picklist table, then the role2picklist will be applicable for this table...
 317  
 318                  $sql="select * from vtiger_$fldname where $fldname=?";
 319                  $res = $adb->pquery($sql,array(decode_html($exist_val)));
 320                  $picklistvalueid = $adb->query_result($res,0,'picklist_valueid');
 321                  if ($picklistvalueid != null) {
 322                      $pick_query="select * from vtiger_role2picklist where picklistvalueid=$picklistvalueid and roleid in (". generateQuestionMarks($roleids) .")";
 323  
 324                      $res_val=$adb->pquery($pick_query,array($roleids));
 325                      $num_val = $adb->num_rows($res_val);
 326                  }
 327                  if($num_val > 0)
 328                  $pick_val = $exist_val;
 329                  else
 330                  $pick_val = $app_strings['LBL_NOT_ACCESSIBLE'];
 331  
 332  
 333              }else
 334              $pick_val = $exist_val;
 335  
 336              return $pick_val;
 337              
 338  }
 339  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1