originalUser = $current_user; $current_user = $user; return $user; } public function doTask($entityData){ if(!vtlib_isModuleActive('Calendar')) { return; } global $adb, $current_user; $userId = $entityData->get('assigned_user_id'); if($userId===null){ $userId = vtws_getWebserviceEntityId('Users', 1); } $baseDate = $entityData->get($this->datefield); if($baseDate == '') { $baseDate = date('Y-m-d'); } $time = explode(' ',$baseDate); if(count($time) < 2) { $time[] = date('H:i'); } preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDate, $match); $baseDate = strtotime($match[0]); $date = strftime('%Y-%m-%d', $baseDate+$this->days*24*60*60*($this->directions=='Before'?-1:1)); $startDate = new DateTimeField($date.' '.$time[1]); $date = $startDate->getDisplayDate(); $fields = array( 'activitytype'=>'Task', 'description'=>$this->description, 'subject'=>$this->todo, 'taskpriority'=>$this->priority, 'taskstatus'=>$this->status, 'assigned_user_id'=>$userId, 'time_start'=> $startDate->getDisplayTime(), 'sendnotification'=>($this->sendNotification!='' && $this->sendNotification!='N')? true: false, 'date_start'=>$date, 'due_date'=>$date, 'visibility'=>'all', 'eventstatus'=>'' ); $moduleName = $entityData->getModuleName(); $adminUser = $this->getAdmin(); $id = $entityData->getId(); if($moduleName=='Contacts'){ $fields['contact_id'] = $id; }else{ $data = vtws_describe('Calendar', $adminUser); $fieldInfo = $data['fields']; foreach($fieldInfo as $field){ if($field['name']=='parent_id'){ $parentIdField = $field; } } $refersTo = $parentIdField['type']['refersTo']; if(in_array($moduleName, $refersTo)){ $fields['parent_id'] = $id; } } vtws_create('Calendar', $fields, $adminUser); global $current_user; $current_user = $this->originalUser; } static function conv12to24hour($timeStr){ $arr = array(); preg_match('/(\d{1,2}):(\d{1,2})(am|pm)/', $timeStr, $arr); if($arr[3]=='am'){ $hours = ((int)$arr[1]) % 12; }else{ $hours = ((int)$arr[1]) % 12 + 12; } return str_pad($hours, 2, '0', STR_PAD_LEFT).':'.str_pad($arr[2], 2, '0', STR_PAD_LEFT); } public function getTimeFieldList() { return array('time'); } } ?>