[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
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 require_once ('include/Webservices/Utils.php'); 11 require_once ("include/Webservices/VtigerCRMObject.php"); 12 require_once ("include/Webservices/VtigerCRMObjectMeta.php"); 13 require_once ("include/Webservices/DataTransform.php"); 14 require_once ("include/Webservices/WebServiceError.php"); 15 require_once 'include/Webservices/ModuleTypes.php'; 16 require_once ('include/Webservices/Create.php'); 17 require_once 'include/Webservices/DescribeObject.php'; 18 require_once 'include/Webservices/WebserviceField.php'; 19 require_once 'include/Webservices/EntityMeta.php'; 20 require_once 'include/Webservices/VtigerWebserviceObject.php'; 21 22 require_once ("modules/Users/Users.php"); 23 24 class VTCreateTodoTask extends VTTask{ 25 public $executeImmediately = true; 26 27 public function getFieldNames(){return array('todo', 'description', 'sendNotification', 'time', 'date', 'status', 'priority', 'days', 'direction', 'datefield', 'sendNotification', 'assigned_user_id');} 28 29 function getAdmin(){ 30 $user = Users::getActiveAdminUser(); 31 global $current_user; 32 $this->originalUser = $current_user; 33 $current_user = $user; 34 return $user; 35 } 36 37 public function doTask($entityData){ 38 if(!vtlib_isModuleActive('Calendar')) { 39 return; 40 } 41 global $adb, $current_user; 42 $userId = $entityData->get('assigned_user_id'); 43 if($userId===null){ 44 $userId = vtws_getWebserviceEntityId('Users', 1); 45 } 46 47 $baseDate = $entityData->get($this->datefield); 48 if($baseDate == '') { 49 $baseDate = date('Y-m-d'); 50 } 51 $time = explode(' ',$baseDate); 52 if(count($time) < 2) { 53 $timeWithSec = Vtiger_Time_UIType::getTimeValueWithSeconds($this->time); 54 $dbInsertDateTime = DateTimeField::convertToDBTimeZone($baseDate.' '.$timeWithSec); 55 $time = $dbInsertDateTime->format('H:i:s'); 56 } else { 57 $time = $time[1]; 58 } 59 preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDate, $match); 60 $baseDate = strtotime($match[0]); 61 $date = strftime('%Y-%m-%d', $baseDate+$this->days*24*60*60*(strtolower($this->direction)=='before'?-1:1)); 62 // Added to check if the user/group is active 63 if(!empty($this->assigned_user_id)) { 64 $userExists = $adb->pquery('SELECT 1 FROM vtiger_users WHERE id = ? AND status = ?', array($this->assigned_user_id, 'Active')); 65 if($adb->num_rows($userExists)) { 66 $assignedUserId = vtws_getWebserviceEntityId('Users', $this->assigned_user_id); 67 $userId = $assignedUserId; 68 } else { 69 $groupExist = $adb->pquery('SELECT 1 FROM vtiger_groups WHERE groupid = ?', array($this->assigned_user_id)); 70 if($adb->num_rows($groupExist)) { 71 $assignedGroupId = vtws_getWebserviceEntityId('Groups', $this->assigned_user_id); 72 $userId = $assignedGroupId; 73 } 74 else{ 75 if($this->assigned_user_id == 'copyParentOwner'){ 76 $userId = $entityData->get('assigned_user_id'); 77 } 78 } 79 } 80 } 81 82 $fields = array( 83 'activitytype'=>'Task', 84 'description'=>$this->description, 85 'subject'=>$this->todo, 86 'taskpriority'=>$this->priority, 87 'taskstatus'=>$this->status, 88 'assigned_user_id'=>$userId, 89 'time_start'=> $time, 90 'sendnotification'=>($this->sendNotification!='' && $this->sendNotification!='N')? 91 true: false, 92 'date_start'=>$date, 93 'due_date'=>$date, 94 'visibility'=>'Private', 95 'eventstatus'=>'' 96 ); 97 $moduleName = $entityData->getModuleName(); 98 $adminUser = $this->getAdmin(); 99 $id = $entityData->getId(); 100 if($moduleName=='Contacts'){ 101 $fields['contact_id'] = $id; 102 }else{ 103 $data = vtws_describe('Calendar', $adminUser); 104 $fieldInfo = $data['fields']; 105 foreach($fieldInfo as $field){ 106 if($field['name']=='parent_id'){ 107 $parentIdField = $field; 108 } 109 } 110 $refersTo = $parentIdField['type']['refersTo']; 111 112 if(in_array($moduleName, $refersTo)){ 113 $fields['parent_id'] = $id; 114 } 115 } 116 117 $todo = vtws_create('Calendar', $fields, $adminUser); 118 $todoIdDetails = vtws_getIdComponents($todo['id']); 119 $entityIdDetails = vtws_getIdComponents($id); 120 121 relateEntities(CRMEntity::getInstance($moduleName), $moduleName, $entityIdDetails[1], 'Calendar', $todoIdDetails[1]); 122 123 global $current_user; 124 $current_user = $this->originalUser; 125 } 126 127 static function conv12to24hour($timeStr){ 128 $arr = array(); 129 preg_match('/(\d{1,2}):(\d{1,2})(am|pm)/', $timeStr, $arr); 130 if($arr[3]=='am'){ 131 $hours = ((int)$arr[1]) % 12; 132 }else{ 133 $hours = ((int)$arr[1]) % 12 + 12; 134 } 135 return str_pad($hours, 2, '0', STR_PAD_LEFT).':'.str_pad($arr[2], 2, '0', STR_PAD_LEFT); 136 } 137 138 public function getTimeFieldList() { 139 return array('time'); 140 } 141 142 } 143 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |