| [ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 * The contents of this file are subject to the SugarCRM Public License Version 1.1.2 4 * ("License"); You may not use this file except in compliance with the 5 * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL 6 * Software distributed under the License is distributed on an "AS IS" basis, 7 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for 8 * the specific language governing rights and limitations under the License. 9 * The Original Code is: SugarCRM Open Source 10 * The Initial Developer of the Original Code is SugarCRM, Inc. 11 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.; 12 * All Rights Reserved. 13 * Contributor(s): ______________________________________. 14 ********************************************************************************/ 15 /********************************************************************************* 16 * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Activities/Activity.php,v 1.26 2005/03/26 10:42:13 rank Exp $ 17 * Description: TODO: To be written. 18 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 19 * All Rights Reserved. 20 * Contributor(s): ______________________________________.. 21 ********************************************************************************/ 22 23 include_once ('config.php'); 24 require_once ('include/logging.php'); 25 require_once ('include/database/PearDatabase.php'); 26 require_once ('modules/Calendar/RenderRelatedListUI.php'); 27 require_once ('data/CRMEntity.php'); 28 29 // Task is used to store customer information. 30 class Activity extends CRMEntity { 31 var $log; 32 var $db; 33 var $reminder_table = 'vtiger_activity_reminder'; 34 var $tab_name = Array('vtiger_crmentity','vtiger_activity'); 35 36 var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_activity'=>'activityid','vtiger_seactivityrel'=>'activityid','vtiger_cntactivityrel'=>'activityid','vtiger_salesmanactivityrel'=>'activityid','vtiger_activity_reminder'=>'activity_id','vtiger_recurringevents'=>'activityid'); 37 38 var $column_fields = Array(); 39 var $sortby_fields = Array('subject','due_date','date_start','smownerid','activitytype'); //Sorting is added for due date and start date 40 41 // This is used to retrieve related vtiger_fields from form posts. 42 var $additional_column_fields = Array('assigned_user_name', 'assigned_user_id', 'contactname', 'contact_phone', 'contact_email', 'parent_name'); 43 44 // This is the list of vtiger_fields that are in the lists. 45 var $list_fields = Array( 46 'Close'=>Array('activity'=>'status'), 47 'Type'=>Array('activity'=>'activitytype'), 48 'Subject'=>Array('activity'=>'subject'), 49 'Related to'=>Array('seactivityrel'=>'activityid'), 50 'Start Date'=>Array('activity'=>'date_start'), 51 'End Date'=>Array('activity'=>'due_date'), 52 'Recurring Type'=>Array('recurringevents'=>'recurringtype'), 53 'Assigned To'=>Array('crmentity'=>'smownerid') 54 ); 55 56 var $range_fields = Array( 57 'name', 58 'date_modified', 59 'start_date', 60 'id', 61 'status', 62 'date_due', 63 'time_start', 64 'description', 65 'contact_name', 66 'priority', 67 'duehours', 68 'dueminutes', 69 'location' 70 ); 71 72 73 var $list_fields_name = Array( 74 'Close'=>'status', 75 'Type'=>'activitytype', 76 'Subject'=>'subject', 77 'Contact Name'=>'lastname', 78 'Related to'=>'activityid', 79 'Start Date'=>'date_start', 80 'End Date'=>'due_date', 81 'Recurring Type'=>'recurringtype', 82 'Assigned To'=>'assigned_user_id'); 83 84 var $list_link_field= 'subject'; 85 86 //Added these variables which are used as default order by and sortorder in ListView 87 var $default_order_by = 'due_date'; 88 var $default_sort_order = 'ASC'; 89 90 function Activity() { 91 $this->log = LoggerManager::getLogger('Calendar'); 92 $this->db = new PearDatabase(); 93 $this->column_fields = getColumnFields('Calendar'); 94 } 95 96 97 function save_module($module) 98 { 99 //Handling module specific save 100 //Insert into seactivity rel 101 if(isset($this->column_fields['parent_id']) && $this->column_fields['parent_id'] != '') 102 { 103 $this->insertIntoEntityTable("vtiger_seactivityrel", $module); 104 } 105 elseif($this->column_fields['parent_id']=='' && $insertion_mode=="edit") 106 { 107 $this->deleteRelation("vtiger_seactivityrel"); 108 } 109 //Insert into cntactivity rel 110 111 if(isset($this->column_fields['contact_id']) && $this->column_fields['contact_id'] != '') 112 { 113 $this->insertIntoEntityTable('vtiger_cntactivityrel', $module); 114 } 115 elseif($this->column_fields['contact_id'] =='' && $insertion_mode=="edit") 116 { 117 $this->deleteRelation('vtiger_cntactivityrel'); 118 } 119 120 //Handling for recurring type 121 //Insert into vtiger_activity_remainder table 122 if(isset($this->column_fields['recurringtype']) && $this->column_fields['recurringtype']!='') 123 $recur_type = trim($this->column_fields['recurringtype']); 124 else 125 $recur_type=''; 126 127 if($recur_type == "--None--") 128 { 129 $this->insertIntoReminderTable('vtiger_activity_reminder',$module,""); 130 } 131 132 //Insert into vtiger_recurring event table 133 $recur_type = trim($this->column_fields['recurringtype']); 134 if($recur_type != "--None--" && $recur_type != '') 135 { 136 $recur_data = getrecurringObjValue(); 137 if(is_object($recur_data)) 138 $this->insertIntoRecurringTable($recur_data); 139 } 140 141 //Handling for invitees 142 if(isset($_REQUEST['inviteesid']) && $_REQUEST['inviteesid']!='') 143 { 144 $selected_users_string = $_REQUEST['inviteesid']; 145 $invitees_array = explode(';',$selected_users_string); 146 $this->insertIntoInviteeTable('vtiger_invitees',$module,$invitees_array); 147 148 } 149 150 //Inserting into sales man activity rel 151 $this->insertIntoSmActivityRel($module); 152 153 154 155 } 156 157 158 /** Function to insert values in vtiger_activity_remainder table for the specified module, 159 * @param $table_name -- table name:: Type varchar 160 * @param $module -- module:: Type varchar 161 */ 162 function insertIntoReminderTable($table_name,$module,$recurid) 163 { 164 global $log; 165 $log->info("in insertIntoReminderTable ".$table_name." module is ".$module); 166 if($_REQUEST['set_reminder'] == 'Yes') 167 { 168 $log->debug("set reminder is set"); 169 $rem_days = $_REQUEST['remdays']; 170 $log->debug("rem_days is ".$rem_days); 171 $rem_hrs = $_REQUEST['remhrs']; 172 $log->debug("rem_hrs is ".$rem_hrs); 173 $rem_min = $_REQUEST['remmin']; 174 $log->debug("rem_minutes is ".$rem_min); 175 $reminder_time = $rem_days * 24 * 60 + $rem_hrs * 60 + $rem_min; 176 $log->debug("reminder_time is ".$reminder_time); 177 if ($recurid == "") 178 { 179 if($_REQUEST['mode'] == 'edit') 180 { 181 $this->activity_reminder($this->id,$reminder_time,0,$recurid,'edit'); 182 } 183 else 184 { 185 $this->activity_reminder($this->id,$reminder_time,0,$recurid,''); 186 } 187 } 188 else 189 { 190 $this->activity_reminder($this->id,$reminder_time,0,$recurid,''); 191 } 192 } 193 elseif($_REQUEST['set_reminder'] == 'No') 194 { 195 $this->activity_reminder($this->id,'0',0,$recurid,'delete'); 196 } 197 } 198 199 200 // Code included by Jaguar - starts 201 /** Function to insert values in vtiger_recurringevents table for the specified tablename,module 202 * @param $recurObj -- Recurring Object:: Type varchar 203 */ 204 function insertIntoRecurringTable(& $recurObj) 205 { 206 global $log,$adb; 207 $log->info("in insertIntoRecurringTable "); 208 $st_date = $recurObj->startdate->get_formatted_date(); 209 $log->debug("st_date ".$st_date); 210 $end_date = $recurObj->enddate->get_formatted_date(); 211 $log->debug("end_date is set ".$end_date); 212 $type = $recurObj->recur_type; 213 $log->debug("type is ".$type); 214 $flag="true"; 215 216 if($_REQUEST['mode'] == 'edit') 217 { 218 $activity_id=$this->id; 219 220 $sql='select min(recurringdate) AS min_date,max(recurringdate) AS max_date, recurringtype, activityid from vtiger_recurringevents where activityid='. $activity_id.' group by activityid, recurringtype'; 221 222 $result = $adb->query($sql); 223 $noofrows = $adb->num_rows($result); 224 for($i=0; $i<$noofrows; $i++) 225 { 226 $recur_type_b4_edit = $adb->query_result($result,$i,"recurringtype"); 227 $date_start_b4edit = $adb->query_result($result,$i,"min_date"); 228 $end_date_b4edit = $adb->query_result($result,$i,"max_date"); 229 } 230 if(($st_date == $date_start_b4edit) && ($end_date==$end_date_b4edit) && ($type == $recur_type_b4_edit)) 231 { 232 if($_REQUEST['set_reminder'] == 'Yes') 233 { 234 $sql = 'delete from vtiger_activity_reminder where activity_id='.$activity_id; 235 $adb->query($sql); 236 $sql = 'delete from vtiger_recurringevents where activityid='.$activity_id; 237 $adb->query($sql); 238 $flag="true"; 239 } 240 elseif($_REQUEST['set_reminder'] == 'No') 241 { 242 $sql = 'delete from vtiger_activity_reminder where activity_id='.$activity_id; 243 $adb->query($sql); 244 $flag="false"; 245 } 246 else 247 $flag="false"; 248 } 249 else 250 { 251 $sql = 'delete from vtiger_activity_reminder where activity_id='.$activity_id; 252 $adb->query($sql); 253 $sql = 'delete from vtiger_recurringevents where activityid='.$activity_id; 254 $adb->query($sql); 255 } 256 } 257 $date_array = $recurObj->recurringdates; 258 if(isset($recurObj->recur_freq) && $recurObj->recur_freq != null) 259 $recur_freq = $recurObj->recur_freq; 260 else 261 $recur_freq = 1; 262 if($recurObj->recur_type == 'Daily' || $recurObj->recur_type == 'Yearly') 263 $recurringinfo = $recurObj->recur_type; 264 elseif($recurObj->recur_type == 'Weekly') 265 { 266 $recurringinfo = $recurObj->recur_type; 267 if($recurObj->dayofweek_to_rpt != null) 268 $recurringinfo = $recurringinfo.'::'.implode('::',$recurObj->dayofweek_to_rpt); 269 } 270 elseif($recurObj->recur_type == 'Monthly') 271 { 272 $recurringinfo = $recurObj->recur_type.'::'.$recurObj->repeat_monthby; 273 if($recurObj->repeat_monthby == 'date') 274 $recurringinfo = $recurringinfo.'::'.$recurObj->rptmonth_datevalue; 275 else 276 $recurringinfo = $recurringinfo.'::'.$recurObj->rptmonth_daytype.'::'.$recurObj->dayofweek_to_rpt[0]; 277 } 278 else 279 { 280 $recurringinfo = ''; 281 } 282 if($flag=="true") 283 { 284 for($k=0; $k< count($date_array); $k++) 285 { 286 $tdate=$date_array[$k]; 287 if($tdate <= $end_date) 288 { 289 $max_recurid_qry = 'select max(recurringid) AS recurid from vtiger_recurringevents;'; 290 $result = $adb->query($max_recurid_qry); 291 $noofrows = $adb->num_rows($result); 292 for($i=0; $i<$noofrows; $i++) 293 { 294 $recur_id = $adb->query_result($result,$i,"recurid"); 295 } 296 $current_id =$recur_id+1; 297 $recurring_insert = "insert into vtiger_recurringevents values ('".$current_id."','".$this->id."','".$tdate."','".$type."','".$recur_freq."','".$recurringinfo."')"; 298 $adb->query($recurring_insert); 299 if($_REQUEST['set_reminder'] == 'Yes') 300 { 301 $this->insertIntoReminderTable("vtiger_activity_reminder",$module,$current_id,''); 302 } 303 } 304 } 305 } 306 } 307 308 309 /** Function to insert values in vtiger_invitees table for the specified module,tablename ,invitees_array 310 * @param $table_name -- table name:: Type varchar 311 * @param $module -- module:: Type varchar 312 * @param $invitees_array Array 313 */ 314 function insertIntoInviteeTable($table_name,$module,$invitees_array) 315 { 316 global $log,$adb; 317 $log->debug("Entering insertIntoInviteeTable(".$table_name.",".$module.",".$invitees_array.") method ..."); 318 foreach($invitees_array as $inviteeid) 319 { 320 if($inviteeid != '') 321 { 322 $query="insert into vtiger_invitees values(".$this->id.",".$inviteeid.")"; 323 $adb->query($query); 324 } 325 } 326 $log->debug("Exiting insertIntoInviteeTable method ..."); 327 328 } 329 330 331 /** Function to insert values in vtiger_salesmanactivityrel table for the specified module 332 * @param $module -- module:: Type varchar 333 */ 334 335 function insertIntoSmActivityRel($module) 336 { 337 global $adb; 338 global $current_user; 339 if($this->mode == 'edit') 340 { 341 342 $sql = "delete from vtiger_salesmanactivityrel where activityid=".$this->id." and smid = ".$this->column_fields['assigned_user_id'].""; 343 $adb->query($sql); 344 345 } 346 $sql_qry = "insert into vtiger_salesmanactivityrel (smid,activityid) values(".$this->column_fields['assigned_user_id'].",".$this->id.")"; 347 $adb->query($sql_qry); 348 349 } 350 351 352 // Mike Crowe Mod --------------------------------------------------------Default ordering for us 353 /** 354 * Function to get sort order 355 * return string $sorder - sortorder string either 'ASC' or 'DESC' 356 */ 357 function getSortOrder() 358 { 359 global $log; $log->debug("Entering getSortOrder() method ..."); 360 if(isset($_REQUEST['sorder'])) 361 $sorder = $_REQUEST['sorder']; 362 else 363 $sorder = (($_SESSION['ACTIVITIES_SORT_ORDER'] != '')?($_SESSION['ACTIVITIES_SORT_ORDER']):($this->default_sort_order)); 364 $log->debug("Exiting getSortOrder method ..."); 365 return $sorder; 366 } 367 368 /** 369 * Function to get order by 370 * return string $order_by - fieldname(eg: 'subject') 371 */ 372 function getOrderBy() 373 { 374 global $log; 375 $log->debug("Entering getOrderBy() method ..."); 376 if (isset($_REQUEST['order_by'])) 377 $order_by = $_REQUEST['order_by']; 378 else 379 $order_by = (($_SESSION['ACTIVITIES_ORDER_BY'] != '')?($_SESSION['ACTIVITIES_ORDER_BY']):($this->default_order_by)); 380 $log->debug("Exiting getOrderBy method ..."); 381 return $order_by; 382 } 383 // Mike Crowe Mod -------------------------------------------------------- 384 385 386 387 //Function Call for Related List -- Start 388 /** 389 * Function to get Activity related Contacts 390 * @param integer $id - activityid 391 * returns related Contacts record in array format 392 */ 393 function get_contacts($id) 394 { 395 global $log; 396 $log->debug("Entering get_contacts(".$id.") method ..."); 397 global $app_strings; 398 399 $focus = new Contacts(); 400 401 $button = ''; 402 403 $returnset = '&return_module=Calendar&return_action=CallRelatedList&activity_mode=Events&return_id='.$id; 404 405 $query = 'select vtiger_users.user_name,vtiger_contactdetails.accountid,vtiger_contactdetails.contactid, vtiger_contactdetails.firstname,vtiger_contactdetails.lastname, vtiger_contactdetails.department, vtiger_contactdetails.title, vtiger_contactdetails.email, vtiger_contactdetails.phone, vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime from vtiger_contactdetails inner join vtiger_cntactivityrel on vtiger_cntactivityrel.contactid=vtiger_contactdetails.contactid inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_contactdetails.contactid left join vtiger_users on vtiger_users.id = vtiger_crmentity.smownerid left join vtiger_activitygrouprelation on vtiger_cntactivityrel.activityid = vtiger_activitygrouprelation.activityid left join vtiger_groups on vtiger_groups.groupname = vtiger_activitygrouprelation.groupname where vtiger_cntactivityrel.activityid='.$id.' and vtiger_crmentity.deleted=0'; 406 $log->debug("Exiting get_contacts method ..."); 407 return GetRelatedList('Calendar','Contacts',$focus,$query,$button,$returnset); 408 } 409 410 /** 411 * Function to get Activity related Users 412 * @param integer $id - activityid 413 * returns related Users record in array format 414 */ 415 416 function get_users($id) 417 { 418 global $log; 419 $log->debug("Entering get_contacts(".$id.") method ..."); 420 global $app_strings; 421 422 $focus = new Users(); 423 424 $button = ''; 425 426 $returnset = '&return_module=Calendar&return_action=CallRelatedList&return_id='.$id; 427 428 $query = 'SELECT vtiger_users.id, vtiger_users.first_name,vtiger_users.last_name, vtiger_users.user_name, vtiger_users.email1, vtiger_users.email2, vtiger_users.status, vtiger_users.is_admin, vtiger_user2role.roleid, vtiger_users.yahoo_id, vtiger_users.phone_home, vtiger_users.phone_work, vtiger_users.phone_mobile, vtiger_users.phone_other, vtiger_users.phone_fax,vtiger_activity.date_start,vtiger_activity.due_date,vtiger_activity.time_start,vtiger_activity.duration_hours,vtiger_activity.duration_minutes from vtiger_users inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.smid=vtiger_users.id inner join vtiger_activity on vtiger_activity.activityid=vtiger_salesmanactivityrel.activityid inner join vtiger_user2role on vtiger_user2role.userid=vtiger_users.id where vtiger_activity.activityid='.$id; 429 $log->debug("Exiting get_users method ..."); 430 return GetRelatedList('Calendar','Users',$focus,$query,$button,$returnset); 431 432 433 } 434 435 /** 436 * Function to get activities for given criteria 437 * @param string $criteria - query string 438 * returns activity records in array format($list) or null value 439 */ 440 function get_full_list($criteria) 441 { 442 global $log; 443 $log->debug("Entering get_full_list(".$criteria.") method ..."); 444 $query = "select vtiger_crmentity.crmid,vtiger_crmentity.smownerid,vtiger_crmentity.setype, vtiger_activity.*, vtiger_contactdetails.lastname, vtiger_contactdetails.firstname, vtiger_contactdetails.contactid from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid= vtiger_activity.activityid left join vtiger_contactdetails on vtiger_contactdetails.contactid= vtiger_cntactivityrel.contactid left join vtiger_seactivityrel on vtiger_seactivityrel.activityid = vtiger_activity.activityid WHERE vtiger_crmentity.deleted=0 ".$criteria; 445 $result =& $this->db->query($query); 446 447 if($this->db->getRowCount($result) > 0){ 448 449 // We have some data. 450 while ($row = $this->db->fetchByAssoc($result)) { 451 foreach($this->list_fields_name as $field) 452 { 453 if (isset($row[$field])) { 454 $this->$field = $row[$field]; 455 } 456 else { 457 $this->$field = ''; 458 } 459 } 460 $list[] = $this; 461 } 462 } 463 if (isset($list)) 464 { 465 $log->debug("Exiting get_full_list method ..."); 466 return $list; 467 } 468 else 469 { 470 $log->debug("Exiting get_full_list method ..."); 471 return null; 472 } 473 474 } 475 476 477 //calendarsync 478 /** 479 * Function to get meeting count 480 * @param string $user_name - User Name 481 * return integer $row["count(*)"] - count 482 */ 483 function getCount_Meeting($user_name) 484 { 485 global $log; 486 $log->debug("Entering getCount_Meeting(".$user_name.") method ..."); 487 $query = "select count(*) from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid where user_name='" .$user_name ."' and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Meeting'"; 488 489 $result = $this->db->query($query,true,"Error retrieving contacts count"); 490 $rows_found = $this->db->getRowCount($result); 491 $row = $this->db->fetchByAssoc($result, 0); 492 $log->debug("Exiting getCount_Meeting method ..."); 493 return $row["count(*)"]; 494 } 495 496 function get_calendars($user_name,$from_index,$offset) 497 { 498 global $log; 499 $log->debug("Entering get_calendars(".$user_name.",".$from_index.",".$offset.") method ..."); 500 $query = "select vtiger_activity.location as location,vtiger_activity.duration_hours as duehours, vtiger_activity.duration_minutes as dueminutes,vtiger_activity.time_start as time_start, vtiger_activity.subject as name,vtiger_crmentity.modifiedtime as date_modified, vtiger_activity.date_start start_date,vtiger_activity.activityid as id,vtiger_activity.status as status, vtiger_crmentity.description as description, vtiger_activity.priority as vtiger_priority, vtiger_activity.due_date as date_due ,vtiger_contactdetails.firstname cfn, vtiger_contactdetails.lastname cln from vtiger_activity inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid=vtiger_activity.activityid left join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_cntactivityrel.contactid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid where user_name='" .$user_name ."' and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Meeting' limit " .$from_index ."," .$offset; 501 $log->debug("Exiting get_calendars method ..."); 502 return $this->process_list_query1($query); 503 } 504 //calendarsync 505 /** 506 * Function to get task count 507 * @param string $user_name - User Name 508 * return integer $row["count(*)"] - count 509 */ 510 function getCount($user_name) 511 { 512 global $log; 513 $log->debug("Entering getCount(".$user_name.") method ..."); 514 $query = "select count(*) from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid where user_name='" .$user_name ."' and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Task'"; 515 516 $result = $this->db->query($query,true,"Error retrieving contacts count"); 517 $rows_found = $this->db->getRowCount($result); 518 $row = $this->db->fetchByAssoc($result, 0); 519 520 $log->debug("Exiting getCount method ..."); 521 return $row["count(*)"]; 522 } 523 524 /** 525 * Function to get list of task for user with given limit 526 * @param string $user_name - User Name 527 * @param string $from_index - query string 528 * @param string $offset - query string 529 * returns tasks in array format 530 */ 531 function get_tasks($user_name,$from_index,$offset) 532 { 533 global $log; 534 $log->debug("Entering get_tasks(".$user_name.",".$from_index.",".$offset.") method ..."); 535 $query = "select vtiger_activity.subject as name,vtiger_crmentity.modifiedtime as date_modified, vtiger_activity.date_start start_date,vtiger_activity.activityid as id,vtiger_activity.status as status, vtiger_crmentity.description as description, vtiger_activity.priority as priority, vtiger_activity.due_date as date_due ,vtiger_contactdetails.firstname cfn, vtiger_contactdetails.lastname cln from vtiger_activity inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid=vtiger_activity.activityid left join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_cntactivityrel.contactid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid where user_name='" .$user_name ."' and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Task' limit " .$from_index ."," .$offset; 536 $log->debug("Exiting get_tasks method ..."); 537 return $this->process_list_query1($query); 538 539 } 540 541 /** 542 * Function to process the activity list query 543 * @param string $query - query string 544 * return array $response - activity lists 545 */ 546 function process_list_query1($query) 547 { 548 global $log; 549 $log->debug("Entering process_list_query1(".$query.") method ..."); 550 $result =& $this->db->query($query,true,"Error retrieving $this->object_name list: "); 551 $list = Array(); 552 $rows_found = $this->db->getRowCount($result); 553 if($rows_found != 0) 554 { 555 $task = Array(); 556 for($index = 0 , $row = $this->db->fetchByAssoc($result, $index); $row && $index <$rows_found;$index++, $row = $this->db->fetchByAssoc($result, $index)) 557 558 { 559 foreach($this->range_fields as $columnName) 560 { 561 if (isset($row[$columnName])) { 562 563 $task[$columnName] = $row[$columnName]; 564 } 565 else 566 { 567 $task[$columnName] = ""; 568 } 569 } 570 571 $task[contact_name] = return_name($row, 'cfn', 'cln'); 572 573 $list[] = $task; 574 } 575 } 576 577 $response = Array(); 578 $response['list'] = $list; 579 $response['row_count'] = $rows_found; 580 $response['next_offset'] = $next_offset; 581 $response['previous_offset'] = $previous_offset; 582 583 584 $log->debug("Exiting process_list_query1 method ..."); 585 return $response; 586 } 587 588 /** 589 * Function to get reminder for activity 590 * @param integer $activity_id - activity id 591 * @param string $reminder_time - reminder time 592 * @param integer $reminder_sent - 0 or 1 593 * @param integer $recurid - recuring eventid 594 * @param string $remindermode - string like 'edit' 595 */ 596 function activity_reminder($activity_id,$reminder_time,$reminder_sent=0,$recurid,$remindermode='') 597 { 598 global $log; 599 $log->debug("Entering vtiger_activity_reminder(".$activity_id.",".$reminder_time.",".$reminder_sent.",".$recurid.",".$remindermode.") method ..."); 600 //Check for vtiger_activityid already present in the reminder_table 601 $query_exist = "SELECT activity_id FROM ".$this->reminder_table." WHERE activity_id = ".$activity_id; 602 $result_exist = $this->db->query($query_exist); 603 604 if($remindermode == 'edit') 605 { 606 if($this->db->num_rows($result_exist) == 1) 607 { 608 $query = "UPDATE ".$this->reminder_table." SET"; 609 $query .=" reminder_sent = ".$reminder_sent.","; 610 $query .=" reminder_time = ".$reminder_time." WHERE activity_id =".$activity_id; 611 } 612 else 613 { 614 $query = "INSERT INTO ".$this->reminder_table." VALUES (".$activity_id.",".$reminder_time.",0,'".$recurid."')"; 615 } 616 } 617 elseif(($remindermode == 'delete') && ($this->db->num_rows($result_exist) == 1)) 618 { 619 $query = "DELETE FROM ".$this->reminder_table." WHERE activity_id = ".$activity_id; 620 } 621 else 622 { 623 $query = "INSERT INTO ".$this->reminder_table." VALUES (".$activity_id.",".$reminder_time.",0,'".$recurid."')"; 624 } 625 $this->db->query($query,true,"Error in processing vtiger_table $this->reminder_table"); 626 $log->debug("Exiting vtiger_activity_reminder method ..."); 627 } 628 629 //Used for vtigerCRM Outlook Add-In 630 /** 631 * Function to get tasks to display in outlookplugin 632 * @param string $username - User name 633 * return string $query - sql query 634 */ 635 function get_tasksforol($username) 636 { 637 global $log,$adb; 638 $log->debug("Entering get_tasksforol(".$username.") method ..."); 639 global $current_user; 640 require_once ("modules/Users/Users.php"); 641 $seed_user=new Users(); 642 $user_id=$seed_user->retrieve_user_id($username); 643 $current_user=$seed_user; 644 $current_user->retrieve_entity_info($user_id, 'Users'); 645 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 646 require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); 647 648 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 649 { 650 $sql1 = "select tablename,columnname from vtiger_field where tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder'"; 651 }else 652 { 653 $profileList = getCurrentUserProfileList(); 654 $sql1 = "select tablename,columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder' and vtiger_field.displaytype in (1,2,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in ".$profileList; 655 } 656 $result1 = $adb->query($sql1); 657 for($i=0;$i < $adb->num_rows($result1);$i++) 658 { 659 $permitted_lists[] = $adb->query_result($result1,$i,'tablename'); 660 $permitted_lists[] = $adb->query_result($result1,$i,'columnname'); 661 /*if($adb->query_result($result1,$i,'columnname') == "parentid") 662 { 663 $permitted_lists[] = 'vtiger_account'; 664 $permitted_lists[] = 'accountname'; 665 }*/ 666 } 667 $permitted_lists = array_chunk($permitted_lists,2); 668 $column_table_lists = array(); 669 for($i=0;$i < count($permitted_lists);$i++) 670 { 671 $column_table_lists[] = implode(".",$permitted_lists[$i]); 672 } 673 674 $query = "select vtiger_activity.activityid as taskid, ".implode(',',$column_table_lists)." from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid 675 inner join vtiger_users on vtiger_users.id = vtiger_crmentity.smownerid 676 left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid=vtiger_activity.activityid 677 left join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_cntactivityrel.contactid 678 left join vtiger_seactivityrel on vtiger_seactivityrel.activityid = vtiger_activity.activityid 679 where vtiger_users.user_name='".$username."' and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Task'"; 680 $log->debug("Exiting get_tasksforol method ..."); 681 return $query; 682 } 683 684 /** 685 * Function to get calendar query for outlookplugin 686 * @param string $username - User name * return string $query - sql query */ 687 function get_calendarsforol($user_name) 688 { 689 global $log,$adb; 690 $log->debug("Entering get_calendarsforol(".$user_name.") method ..."); 691 global $current_user; 692 require_once ("modules/Users/Users.php"); 693 $seed_user=new Users(); 694 $user_id=$seed_user->retrieve_user_id($user_name); 695 $current_user=$seed_user; 696 $current_user->retrieve_entity_info($user_id, 'Users'); 697 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 698 require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); 699 700 if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) 701 { 702 $sql1 = "select tablename,columnname from vtiger_field where tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder'"; 703 }else 704 { 705 $profileList = getCurrentUserProfileList(); 706 $sql1 = "select tablename,columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder' and vtiger_field.displaytype in (1,2,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in ".$profileList; 707 } 708 $result1 = $adb->query($sql1); 709 for($i=0;$i < $adb->num_rows($result1);$i++) 710 { 711 $permitted_lists[] = $adb->query_result($result1,$i,'tablename'); 712 $permitted_lists[] = $adb->query_result($result1,$i,'columnname'); 713 /*if($adb->query_result($result1,$i,'columnname') == "parentid") 714 { 715 $permitted_lists[] = 'vtiger_account'; 716 $permitted_lists[] = 'accountname'; 717 }*/ 718 } 719 $permitted_lists = array_chunk($permitted_lists,2); 720 $column_table_lists = array(); 721 for($i=0;$i < count($permitted_lists);$i++) 722 { 723 $column_table_lists[] = implode(".",$permitted_lists[$i]); 724 } 725 726 $query = "select vtiger_activity.activityid as clndrid, ".implode(',',$column_table_lists)." from vtiger_activity 727 inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid 728 inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid 729 left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid=vtiger_activity.activityid 730 left join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_cntactivityrel.contactid 731 left join vtiger_seactivityrel on vtiger_seactivityrel.activityid = vtiger_activity.activityid 732 inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid 733 where vtiger_users.user_name='".$user_name."' and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Meeting'"; 734 $log->debug("Exiting get_calendarsforol method ..."); 735 return $query; 736 } 737 //End 738 739 } 740 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |