/** * Function to get the record model based on the request parameters * @param Vtiger_Request $request * @return Vtiger_Record_Model or Module specific Record Model instance */ public function getRecordModelsFromRequest(Vtiger_Request $request) { $moduleName = $request->getModule(); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $recordIds = $this->getRecordsListFromRequest($request); $recordModels = array(); $fieldModelList = $moduleModel->getFields(); foreach ($recordIds as $recordId) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleModel); $recordModel->set('id', $recordId); $recordModel->set('mode', 'edit'); foreach ($fieldModelList as $fieldName => $fieldModel) { $fieldValue = $request->get($fieldName, null); $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } else { if ($fieldDataType === 'date') { $fieldValue = $fieldModel->getUITypeModel()->getDBInsertValue($fieldValue); } } if (isset($fieldValue) && $fieldValue != null && !is_array($fieldValue)) { $fieldValue = trim($fieldValue); $recordModel->set($fieldName, $fieldValue); } } $recordModels[$recordId] = $recordModel; } return $recordModels; }
public function createFollowupEvent(Vtiger_Request $request) { $recordId = $request->get('record'); $recordModel = Vtiger_Record_Model::getInstanceById($recordId); $subject = $recordModel->get('subject'); $followupSubject = "[Followup] " . $subject; $recordModel->set('subject', $followupSubject); //followup event is Planned $recordModel->set('eventstatus', "Planned"); $activityType = $recordModel->get('activitytype'); if ($activityType == "Call") { $eventDuration = $request->get('defaultCallDuration'); } else { $eventDuration = $request->get('defaultOtherEventDuration'); } $followupStartTime = Vtiger_Time_UIType::getTimeValueWithSeconds($request->get('followup_time_start')); $followupStartDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('followup_date_start') . " " . $followupStartTime); list($followupStartDate, $followupStartTime) = explode(' ', $followupStartDateTime); //Duration of followup event based on activitytype $durationMS = $eventDuration * 60; $followupStartDateTimeMS = strtotime($followupStartDateTime); $followupEndDateTimeMS = $followupStartDateTimeMS + $durationMS; $followupEndDateTime = date("Y-m-d H:i:s", $followupEndDateTimeMS); list($followupEndDate, $followupEndTime) = explode(' ', $followupEndDateTime); $recordModel->set('date_start', $followupStartDate); $recordModel->set('time_start', $followupStartTime); $recordModel->set('due_date', $followupEndDate); $recordModel->set('time_end', $followupEndTime); $recordModel->save(); $response = new Vtiger_Response(); $result = array('created' => true); $response->setResult($result); $response->emit(); }
protected function getRecordModelFromRequest(Vtiger_Request $request) { $moduleName = $request->getModule(); $recordId = $request->get('record'); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); if (!empty($recordId)) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); $modelData = $recordModel->getData(); $recordModel->set('id', $recordId); $recordModel->set('mode', 'edit'); } else { $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $modelData = $recordModel->getData(); $recordModel->set('mode', ''); } $fieldModelList = $moduleModel->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { if (in_array($fieldName, array('header_content', 'content', 'footer_content'))) { $fieldValue = $request->getRaw($fieldName, null); } else { $fieldValue = $request->get($fieldName, null); } $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } } return $recordModel; }
/** * Function to save record * @param <Vtiger_Request> $request - values of the record * @return <RecordModel> - record Model of saved record */ public function saveRecord($request) { $adb = PearDatabase::getInstance(); $recordModel = $this->getRecordModelFromRequest($request); $recordModel->save(); $originalRecordId = $recordModel->getId(); if ($request->get('relationOperation')) { $parentModuleName = $request->get('sourceModule'); $parentModuleModel = Vtiger_Module_Model::getInstance($parentModuleName); $parentRecordId = $request->get('sourceRecord'); $relatedModule = $recordModel->getModule(); if ($relatedModule->getName() == 'Events') { $relatedModule = Vtiger_Module_Model::getInstance('Calendar'); } $relatedRecordId = $recordModel->getId(); $relationModel = Vtiger_Relation_Model::getInstance($parentModuleModel, $relatedModule); $relationModel->addRelation($parentRecordId, $relatedRecordId); } // Handled to save follow up event $followupMode = $request->get('followup'); //Start Date and Time values $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($request->get('followup_time_start')); $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('followup_date_start') . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); $subject = $request->get('subject'); if ($followupMode == 'on' && $startTime != '' && $startDate != '') { $recordModel->set('eventstatus', 'Planned'); $recordModel->set('subject', '[Followup] ' . $subject); $recordModel->set('date_start', $startDate); $recordModel->set('time_start', $startTime); $currentUser = Users_Record_Model::getCurrentUserModel(); $activityType = $recordModel->get('activitytype'); if ($activityType == 'Call') { $minutes = $currentUser->get('callduration'); } else { $minutes = $currentUser->get('othereventduration'); } $dueDateTime = date('Y-m-d H:i:s', strtotime("{$startDateTime}+{$minutes} minutes")); list($startDate, $startTime) = explode(' ', $dueDateTime); $recordModel->set('due_date', $startDate); $recordModel->set('time_end', $startTime); $recordModel->set('recurringtype', ''); $recordModel->set('mode', 'create'); $recordModel->save(); $heldevent = true; } //TODO: remove the dependency on $_REQUEST if ($_REQUEST['recurringtype'] != '' && $_REQUEST['recurringtype'] != '--None--') { vimport('~modules/Calendar/RepeatEvents.php'); $focus = new Activity(); //get all the stored data to this object $focus->column_fields = $recordModel->getData(); Calendar_RepeatEvents::repeatFromRequest($focus); } return $recordModel; }
/** * Function to get the record model based on the request parameters * @param Vtiger_Request $request * @return Vtiger_Record_Model or Module specific Record Model instance */ function getRecordModelsFromRequest(Vtiger_Request $request) { $moduleName = $request->getModule(); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $recordIds = $this->getRecordsListFromRequest($request); if (empty($recordIds) && $request->get('selected_ids') == 'all') { $db = PearDatabase::getInstance(); $sql = "SELECT `id` FROM `vtiger_users`"; $result = $db->query($sql, true); $uNum = $db->num_rows($result); if ($uNum > 0) { $recordIds = array(); for ($i = 0; $i < $uNum; $i++) { $recordIds[] = $db->query_result($result, $i, 'id'); } } } $recordModels = array(); $fieldModelList = $moduleModel->getFields(); foreach ($recordIds as $recordId) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleModel); $recordModel->set('id', $recordId); $recordModel->set('mode', 'edit'); foreach ($fieldModelList as $fieldName => $fieldModel) { $fieldValue = $request->get($fieldName, null); $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if (isset($fieldValue) && $fieldValue != null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } else { $uiType = $fieldModel->get('uitype'); if ($uiType == 70) { $recordModel->set($fieldName, $recordModel->get($fieldName)); } else { $uiTypeModel = $fieldModel->getUITypeModel(); $recordModel->set($fieldName, $uiTypeModel->getUserRequestValue($recordModel->get($fieldName))); } } } $recordModels[$recordId] = $recordModel; } return $recordModels; }
/** * Function to get the record model based on the request parameters * @param Vtiger_Request $request * @return Vtiger_Record_Model or Module specific Record Model instance */ function getRecordModelsFromRequest(Vtiger_Request $request) { global $log; $log->debug("Entering ./actions/MassSave.php::getRecordModelsFromRequest"); $moduleName = $request->getModule(); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $recordIds = $this->getRecordsListFromRequest($request); $recordModels = array(); $fieldModelList = $moduleModel->getFields(); foreach ($recordIds as $recordId) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleModel); $recordModel->set('id', $recordId); $recordModel->set('mode', 'edit'); foreach ($fieldModelList as $fieldName => $fieldModel) { $fieldValue = $request->get($fieldName, null); $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if (isset($fieldValue) && $fieldValue != null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } else { $uiType = $fieldModel->get('uitype'); if ($uiType == 70) { $recordModel->set($fieldName, $recordModel->get($fieldName)); } else { $uiTypeModel = $fieldModel->getUITypeModel(); $recordModel->set($fieldName, $uiTypeModel->getUserRequestValue($recordModel->get($fieldName))); } } } $recordModels[$recordId] = $recordModel; } return $recordModels; }
/** * Function to get the record model based on the request parameters * @param Vtiger_Request $request * @return Vtiger_Record_Model or Module specific Record Model instance */ protected function getRecordModelFromRequest(Vtiger_Request $request) { $moduleName = $request->getModule(); $recordId = $request->get('record'); $user = Users_Record_Model::getCurrentUserModel(); $allDay = $request->get('allday'); if ('on' == $allDay) { $request->set('time_start', $user->get('start_hour')); $request->set('time_end', $user->get('end_hour')); } $moduleModel = Vtiger_Module_Model::getInstance($moduleName); if (!empty($recordId)) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); $modelData = $recordModel->getData(); $recordModel->set('id', $recordId); $recordModel->set('mode', 'edit'); //Due to dependencies on the activity_reminder api in Activity.php(5.x) $_REQUEST['mode'] = 'edit'; } else { $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $modelData = $recordModel->getData(); $recordModel->set('mode', ''); } $fieldModelList = $moduleModel->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { $fieldValue = $request->get($fieldName, null); // For custom time fields in Calendar, it was not converting to db insert format(sending as 10:00 AM/PM) $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } // End if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } } //Start Date and Time values $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($request->get('time_start')); $startDate = Vtiger_Date_UIType::getDBInsertedValue($request->get('date_start')); if ($startTime) { $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($startTime); $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('date_start') . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); } $recordModel->set('date_start', $startDate); $recordModel->set('time_start', $startTime); //End Date and Time values $endTime = $request->get('time_end'); $endDate = Vtiger_Date_UIType::getDBInsertedValue($request->get('due_date')); if ($endTime) { $endTime = Vtiger_Time_UIType::getTimeValueWithSeconds($endTime); $endDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('due_date') . " " . $endTime); list($endDate, $endTime) = explode(' ', $endDateTime); } $recordModel->set('time_end', $endTime); $recordModel->set('due_date', $endDate); $activityType = $request->get('activitytype'); if (empty($activityType)) { $recordModel->set('activitytype', 'Task'); $recordModel->set('visibility', 'Private'); } //Due to dependencies on the older code $setReminder = $request->get('set_reminder'); if ($setReminder) { $_REQUEST['set_reminder'] = 'Yes'; } else { $_REQUEST['set_reminder'] = 'No'; } $time = strtotime($request->get('time_end')) - strtotime($request->get('time_start')); $diffinSec = strtotime($request->get('due_date')) - strtotime($request->get('date_start')); $diff_days = floor($diffinSec / (60 * 60 * 24)); $hours = (double) $time / 3600 + $diff_days * 24; $minutes = ((double) $hours - (int) $hours) * 60; $recordModel->set('duration_hours', (int) $hours); $recordModel->set('duration_minutes', round($minutes, 0)); return $recordModel; }
/** * Function to get the record model based on the request parameters * @param Vtiger_Request $request * @return Vtiger_Record_Model or Module specific Record Model instance */ public function getRecordModelFromRequest(Vtiger_Request $request) { $moduleName = $request->getModule(); $recordId = $request->get('record'); if ($request->get('field') == 'enable_recurring') { $enableRecurrence = true; } if (!empty($recordId)) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); $recordModel->set('id', $recordId); $recordModel->set('mode', 'edit'); $fieldModelList = $recordModel->getModule()->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { //For not converting createdtime and modified time to user format $uiType = $fieldModel->get('uitype'); if ($uiType == 70) { $fieldValue = $recordModel->get($fieldName); } else { $fieldValue = $fieldModel->getUITypeModel()->getUserRequestValue($recordModel->get($fieldName)); } if ($fieldName === $request->get('field')) { $fieldValue = $request->get('value'); } /** * If field is enable recurrence then we need to pass related fields of * recurrence to save,because untill enable recurrence is checked,the * related field values wont get saved */ if ($enableRecurrence) { $requestFieldValue = $request->get($fieldName); if ($requestFieldValue != '') { $fieldValue = $request->get($fieldName); } } $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } $recordModel->set($fieldName, $fieldValue); } } else { $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $recordModel->set('mode', ''); $fieldModelList = $moduleModel->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { if ($request->has($fieldName)) { $fieldValue = $request->get($fieldName, null); } else { $fieldValue = $fieldModel->getDefaultFieldValue(); } $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } } } return $recordModel; }
function Events($request, $moduleName) { $currentUser = Users_Record_Model::getCurrentUserModel(); $viewer = $this->getViewer($request); $record = $request->get('record'); if (!empty($record) && $request->get('isDuplicate') == true) { $recordModel = Vtiger_Record_Model::getInstanceById($record, $moduleName); $viewer->assign('MODE', ''); } else { if (!empty($record)) { $recordModel = Vtiger_Record_Model::getInstanceById($record, $moduleName); $viewer->assign('MODE', 'edit'); $viewer->assign('RECORD_ID', $record); } else { $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $viewer->assign('MODE', ''); } } $eventModule = Vtiger_Module_Model::getInstance($moduleName); $recordModel->setModuleFromInstance($eventModule); $moduleModel = $recordModel->getModule(); $fieldList = $moduleModel->getFields(); $requestFieldList = array_intersect_key($request->getAll(), $fieldList); foreach ($requestFieldList as $fieldName => $fieldValue) { $fieldModel = $fieldList[$fieldName]; $specialField = false; // We collate date and time part together in the EditView UI handling // so a bit of special treatment is required if we come from QuickCreate if (empty($record) && ($fieldName == 'time_start' || $fieldName == 'time_end') && !empty($fieldValue)) { $specialField = true; // Convert the incoming user-picked time to GMT time // which will get re-translated based on user-time zone on EditForm $fieldValue = DateTimeField::convertToDBTimeZone($fieldValue)->format("H:i"); } if (empty($record) && ($fieldName == 'date_start' || $fieldName == 'due_date') && !empty($fieldValue)) { if ($fieldName == 'date_start') { $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($requestFieldList['time_start']); $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($fieldValue . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); $fieldValue = Vtiger_Date_UIType::getDisplayDateValue($startDate); } else { $endTime = Vtiger_Time_UIType::getTimeValueWithSeconds($requestFieldList['time_end']); $endDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($fieldValue . " " . $endTime); list($endDate, $endTime) = explode(' ', $endDateTime); $fieldValue = Vtiger_Date_UIType::getDisplayDateValue($endDate); } } if ($fieldModel->isEditable() || $specialField) { $recordModel->set($fieldName, $fieldModel->getDBInsertValue($fieldValue)); } } $recordStructureInstance = Vtiger_RecordStructure_Model::getInstanceFromRecordModel($recordModel, Vtiger_RecordStructure_Model::RECORD_STRUCTURE_MODE_EDIT); $viewMode = $request->get('view_mode'); if (!empty($viewMode)) { $viewer->assign('VIEW_MODE', $viewMode); } $userChangedEndDateTime = $request->get('userChangedEndDateTime'); //If followup value is passed from request to process the value and sent to client $requestFollowUpDate = $request->get('followup_date_start'); $requestFollowUpTime = $request->get('followup_time_start'); $followUpStatus = $request->get('followup'); $eventStatus = $request->get('eventstatus'); if (!empty($requestFollowUpDate)) { $followUpDate = $requestFollowUpDate; } if (!empty($requestFollowUpTime)) { $followUpTime = $requestFollowUpTime; } if ($followUpStatus == 'on') { $viewer->assign('FOLLOW_UP_STATUS', TRUE); } if ($eventStatus == 'Held') { $viewer->assign('SHOW_FOLLOW_UP', TRUE); } else { $viewer->assign('SHOW_FOLLOW_UP', FALSE); } $viewer->assign('USER_CHANGED_END_DATE_TIME', $userChangedEndDateTime); $viewer->assign('FOLLOW_UP_DATE', $followUpDate); $viewer->assign('FOLLOW_UP_TIME', $followUpTime); $viewer->assign('RECURRING_INFORMATION', $recordModel->getRecurrenceInformation()); $viewer->assign('TOMORROWDATE', Vtiger_Date_UIType::getDisplayDateValue(date('Y-m-d', time() + 86400))); $viewer->assign('RECORD_STRUCTURE_MODEL', $recordStructureInstance); $viewer->assign('RECORD_STRUCTURE', $recordStructureInstance->getStructure()); $viewer->assign('MODULE', $moduleName); $viewer->assign('CURRENTDATE', date('Y-n-j')); $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel()); $existingRelatedContacts = $recordModel->getRelatedContactInfo(); //To add contact ids that is there in the request . Happens in gotoFull form mode of quick create $requestContactIdValue = $request->get('contact_id'); if (!empty($requestContactIdValue)) { $existingRelatedContacts[] = array('name' => Vtiger_Util_Helper::getRecordName($requestContactIdValue), 'id' => $requestContactIdValue); } $viewer->assign('RELATED_CONTACTS', $existingRelatedContacts); $isRelationOperation = $request->get('relationOperation'); //if it is relation edit $viewer->assign('IS_RELATION_OPERATION', $isRelationOperation); if ($isRelationOperation) { $viewer->assign('SOURCE_MODULE', $request->get('sourceModule')); $viewer->assign('SOURCE_RECORD', $request->get('sourceRecord')); } $picklistDependencyDatasource = Vtiger_DependencyPicklist::getPicklistDependencyDatasource($moduleName); $accessibleUsers = $currentUser->getAccessibleUsers(); $viewer->assign('PICKIST_DEPENDENCY_DATASOURCE', Zend_Json::encode($picklistDependencyDatasource)); $viewer->assign('ACCESSIBLE_USERS', $accessibleUsers); $viewer->assign('INVITIES_SELECTED', $recordModel->getInvities()); $viewer->assign('CURRENT_USER', $currentUser); $viewer->view('EditView.tpl', $moduleName); }
/** * Process the request to perform relationship operations * @global Users Instance $currentUserModel * @global PearDataBase Instance $adb * @global String $currentModule * @param Vtiger_Request $request * @return boolean */ public function process(Vtiger_Request $request) { $currentUserModel = Users_Record_Model::getCurrentUserModel(); $response = new Vtiger_Response(true); $viewer = $this->getViewer($request); if ('find' == $this->getOperationArg($request)) { $this->skipConnection = true; // No need to connect to mailbox here, improves performance // Check if the message is already linked. $linkedto = MailManager_Relate_Action::associatedLink($request->get('_msguid')); // If the message was not linked, lookup for matching records, using FROM address if (empty($linkedto)) { $results = array(); $modules = array(); $allowedModules = $this->getCurrentUserMailManagerAllowedModules(); foreach (self::$MODULES as $MODULE) { if (!in_array($MODULE, $allowedModules)) { continue; } $from = $request->get('_mfrom'); if (empty($from)) { continue; } $results[$MODULE] = $this->lookupModuleRecordsWithEmail($MODULE, $from); $describe = $this->ws_describe($MODULE); $modules[$MODULE] = array('label' => $describe['label'], 'name' => textlength_check($describe['name']), 'id' => $describe['idPrefix']); // If look is found in a module, skip rest. - for performance //if (!empty($results[$MODULE])) break; } $viewer->assign('LOOKUPS', $results); $viewer->assign('MODULES', $modules); } else { $viewer->assign('LINKEDTO', $linkedto); } $viewer->assign('LINK_TO_AVAILABLE_ACTIONS', $this->linkToAvailableActions()); $viewer->assign('ALLOWED_MODULES', $allowedModules); $viewer->assign('MSGNO', $request->get('_msgno')); $viewer->assign('FOLDER', $request->get('_folder')); $response->setResult(array('ui' => $viewer->view('Relationship.tpl', 'MailManager', true))); } else { if ('link' == $this->getOperationArg($request)) { $linkto = $request->get('_mlinkto'); $foldername = $request->get('_folder'); $connector = $this->getConnector($foldername); // This is to handle larger uploads $memory_limit = MailManager_Config_Model::get('MEMORY_LIMIT'); ini_set('memory_limit', $memory_limit); $mail = $connector->openMail($request->get('_msgno')); $mail->attachments(); // Initialize attachments $linkedto = MailManager_Relate_Action::associate($mail, $linkto); $viewer->assign('LINK_TO_AVAILABLE_ACTIONS', $this->linkToAvailableActions()); $viewer->assign('ALLOWED_MODULES', $this->getCurrentUserMailManagerAllowedModules()); $viewer->assign('LINKEDTO', $linkedto); $viewer->assign('MSGNO', $request->get('_msgno')); $viewer->assign('FOLDER', $foldername); $response->setResult(array('ui' => $viewer->view('Relationship.tpl', 'MailManager', true))); } else { if ('create_wizard' == $this->getOperationArg($request)) { $moduleName = $request->get('_mlinktotype'); $parent = $request->get('_mlinkto'); $foldername = $request->get('_folder'); $connector = $this->getConnector($foldername); $mail = $connector->openMail($request->get('_msgno')); $formData = $this->processFormData($mail); foreach ($formData as $key => $value) { $request->set($key, $value); } $request->set('module', $moduleName); // Delegate QuickCreate FormUI to the target view controller of module. $quickCreateviewClassName = $moduleName . '_QuickCreateAjax_View'; if (!class_exists($quickCreateviewClassName)) { $quickCreateviewClassName = 'Vtiger_QuickCreateAjax_View'; } $quickCreateViewController = new $quickCreateviewClassName(); $quickCreateViewController->process($request); // UI already sent $response = false; } else { if ('create' == $this->getOperationArg($request)) { $linkModule = $request->get('_mlinktotype'); $parent = $request->get('_mlinkto'); $foldername = $request->get('_folder'); if (!empty($foldername)) { // This is to handle larger uploads $memory_limit = MailManager_Config_Model::get('MEMORY_LIMIT'); ini_set('memory_limit', $memory_limit); $connector = $this->getConnector($foldername); $mail = $connector->openMail($request->get('_msgno')); $attachments = $mail->attachments(); // Initialize attachments } $linkedto = MailManager_Relate_Action::getSalesEntityInfo($parent); $recordModel = Vtiger_Record_Model::getCleanInstance($linkModule); $fields = $recordModel->getModule()->getFields(); foreach ($fields as $fieldName => $fieldModel) { if ($request->has($fieldName)) { $fieldValue = $request->get($fieldName); $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } $recordModel->set($fieldName, $fieldValue); } } switch ($linkModule) { case 'Calendar': $activityType = $recordModel->get('activitytype'); if (!$activityType) { $activityType = 'Task'; } $recordModel->set('activitytype', $activityType); //Start Date and Time values $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($request->get('time_start')); $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('date_start') . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); $recordModel->set('date_start', $startDate); $recordModel->set('time_start', $startTime); //End Date and Time values $endDate = Vtiger_Date_UIType::getDBInsertedValue($request->get('due_date')); if ($activityType != 'Task') { $endTime = Vtiger_Time_UIType::getTimeValueWithSeconds($request->get('time_end')); $endDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('due_date') . " " . $endTime); list($endDate, $endTime) = explode(' ', $endDateTime); } else { $endTime = ''; } $recordModel->set('time_end', $endTime); $recordModel->set('due_date', $endDate); if ($parent) { if ($linkedto['module'] == 'Contacts') { $recordModel->set('contact_id', $parent); } else { $recordModel->set('parent_id', $parent); } } $recordModel->set('visibility', 'Public'); break; case 'HelpDesk': $from = $mail->from(); if ($parent) { if ($linkedto['module'] == 'Contacts') { $referenceFieldName = 'contact_id'; } elseif ($linkedto['module'] == 'Accounts') { $referenceFieldName = 'parent_id'; } } $recordModel->set($referenceFieldName, $this->setParentForHelpDesk($parent, $from)); break; case 'ModComments': $recordModel->set('assigned_user_id', $currentUserModel->getId()); $recordModel->set('commentcontent', $request->getRaw('commentcontent')); $recordModel->set('userid', $currentUserModel->getId()); $recordModel->set('creator', $currentUserModel->getId()); $recordModel->set('related_to', $parent); break; } try { $recordModel->save(); // This condition is added so that emails are not created for Tickets and Todo without Parent, // as there is no way to relate them if (empty($parent) && $linkModule != 'HelpDesk' && $linkModule != 'Calendar') { $linkedto = MailManager_Relate_Action::associate($mail, $recordModel->getId()); } if ($linkModule === 'Calendar') { // Handled to save follow up event $followupMode = $request->get('followup'); //Start Date and Time values $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($request->get('followup_time_start')); $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('followup_date_start') . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); $subject = $request->get('subject'); if ($followupMode == 'on' && $startTime != '' && $startDate != '') { $recordModel->set('eventstatus', 'Planned'); $recordModel->set('subject', '[Followup] ' . $subject); $recordModel->set('date_start', $startDate); $recordModel->set('time_start', $startTime); $currentUser = Users_Record_Model::getCurrentUserModel(); $activityType = $recordModel->get('activitytype'); if ($activityType == 'Call') { $minutes = $currentUser->get('callduration'); } else { $minutes = $currentUser->get('othereventduration'); } $dueDateTime = date('Y-m-d H:i:s', strtotime("{$startDateTime}+{$minutes} minutes")); list($startDate, $startTime) = explode(' ', $dueDateTime); $recordModel->set('due_date', $startDate); $recordModel->set('time_end', $startTime); $recordModel->set('recurringtype', ''); $recordModel->set('mode', 'create'); $recordModel->save(); } } // add attachments to the tickets as Documents if ($linkModule == 'HelpDesk' && !empty($attachments)) { $relationController = new MailManager_Relate_Action(); $relationController->__SaveAttachements($mail, $linkModule, $recordModel); } $viewer->assign('MSGNO', $request->get('_msgno')); $viewer->assign('LINKEDTO', $linkedto); $viewer->assign('ALLOWED_MODULES', $this->getCurrentUserMailManagerAllowedModules()); $viewer->assign('LINK_TO_AVAILABLE_ACTIONS', $this->linkToAvailableActions()); $viewer->assign('FOLDER', $foldername); $response->setResult(array('ui' => $viewer->view('Relationship.tpl', 'MailManager', true))); } catch (Exception $e) { $response->setResult(array('ui' => '', 'error' => $e)); } } else { if ('savedraft' == $this->getOperationArg($request)) { $connector = $this->getConnector('__vt_drafts'); $draftResponse = $connector->saveDraft($request); $response->setResult($draftResponse); } else { if ('saveattachment' == $this->getOperationArg($request)) { $connector = $this->getConnector('__vt_drafts'); $uploadResponse = $connector->saveAttachment($request); $response->setResult($uploadResponse); } else { if ('commentwidget' == $this->getOperationArg($request)) { $viewer->assign('LINKMODULE', $request->get('_mlinktotype')); $viewer->assign('PARENT', $request->get('_mlinkto')); $viewer->assign('MSGNO', $request->get('_msgno')); $viewer->assign('FOLDER', $request->get('_folder')); $viewer->view('MailManagerCommentWidget.tpl', 'MailManager'); $response = false; } } } } } } } return $response; }
/** * Function to get the record model based on the request parameters * @param Vtiger_Request $request * @return Vtiger_Record_Model or Module specific Record Model instance */ public function getRecordModelFromRequest(Vtiger_Request $request) { $moduleName = $request->getModule(); $recordId = $request->get('record'); if (!empty($recordId)) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); $recordModel->set('id', $recordId); $recordModel->set('mode', 'edit'); $fieldModelList = $recordModel->getModule()->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { $fieldValue = $fieldModel->getUITypeModel()->getUserRequestValue($recordModel->get($fieldName)); if ($fieldName === $request->get('field')) { $fieldValue = $request->get('value'); } $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } $recordModel->set($fieldName, $fieldValue); } } else { $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $recordModel->set('mode', ''); $fieldModelList = $moduleModel->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { if ($request->has($fieldName)) { $fieldValue = $request->get($fieldName, null); } else { $fieldValue = $fieldModel->getDefaultFieldValue(); } $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } } } return $recordModel; }
public function process(Vtiger_Request $request) { $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $record = $request->get('record'); if (!empty($record) && $request->get('isDuplicate') == true) { $recordModel = $this->record ? $this->record : Vtiger_Record_Model::getInstanceById($record, $moduleName); $viewer->assign('MODE', ''); $recordModel->set('id', ''); //While Duplicating record, If the related record is deleted then we are removing related record info in record model $mandatoryFieldModels = $recordModel->getModule()->getMandatoryFieldModels(); foreach ($mandatoryFieldModels as $fieldModel) { if ($fieldModel->isReferenceField()) { $fieldName = $fieldModel->get('name'); if (Vtiger_Util_Helper::checkRecordExistance($recordModel->get($fieldName))) { $recordModel->set($fieldName, ''); } } } } else { if (!empty($record)) { $recordModel = $this->record ? $this->record : Vtiger_Record_Model::getInstanceById($record, $moduleName); $viewer->assign('RECORD_ID', $record); $viewer->assign('MODE', 'edit'); } else { $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $referenceId = $request->get('reference_id'); if ($referenceId) { $parentRecordModel = Vtiger_Record_Model::getInstanceById($referenceId); $recordModel->setRecordFieldValues($parentRecordModel); } $viewer->assign('MODE', ''); } } if (!$this->record) { $this->record = $recordModel; } $moduleModel = $recordModel->getModule(); $fieldList = $moduleModel->getFields(); $requestFieldList = array_intersect_key($request->getAll(), $fieldList); foreach ($requestFieldList as $fieldName => $fieldValue) { $fieldModel = $fieldList[$fieldName]; $specialField = false; // We collate date and time part together in the EditView UI handling // so a bit of special treatment is required if we come from QuickCreate if ($moduleName == 'Calendar' && empty($record) && $fieldName == 'time_start' && !empty($fieldValue)) { $specialField = true; // Convert the incoming user-picked time to GMT time // which will get re-translated based on user-time zone on EditForm $fieldValue = DateTimeField::convertToDBTimeZone($fieldValue)->format("H:i"); } if ($moduleName == 'Calendar' && empty($record) && $fieldName == 'date_start' && !empty($fieldValue)) { $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($requestFieldList['time_start']); $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($fieldValue . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); $fieldValue = Vtiger_Date_UIType::getDisplayDateValue($startDate); } if ($fieldModel->isEditable() || $specialField) { $recordModel->set($fieldName, $fieldModel->getDBInsertValue($fieldValue)); } } $recordStructureInstance = Vtiger_RecordStructure_Model::getInstanceFromRecordModel($recordModel, Vtiger_RecordStructure_Model::RECORD_STRUCTURE_MODE_EDIT); $picklistDependencyDatasource = Vtiger_DependencyPicklist::getPicklistDependencyDatasource($moduleName); $viewer->assign('PICKIST_DEPENDENCY_DATASOURCE', Zend_Json::encode($picklistDependencyDatasource)); $mappingRelatedField = $moduleModel->getMappingRelatedField($moduleName); $viewer->assign('MAPPING_RELATED_FIELD', Zend_Json::encode($mappingRelatedField)); $viewer->assign('RECORD_STRUCTURE_MODEL', $recordStructureInstance); $viewer->assign('RECORD_STRUCTURE', $recordStructureInstance->getStructure()); $viewer->assign('MODULE', $moduleName); $viewer->assign('MODULE_TYPE', $moduleModel->getModuleType()); $viewer->assign('RECORD', $recordModel); $viewer->assign('BLOCK_LIST', $moduleModel->getBlocks()); $viewer->assign('CURRENTDATE', date('Y-n-j')); $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel()); $viewer->assign('APIADDRESS', Settings_ApiAddress_Module_Model::getInstance('Settings:ApiAddress')->getConfig()); $viewer->assign('APIADDRESS_ACTIVE', Settings_ApiAddress_Module_Model::isActive()); $isRelationOperation = $request->get('relationOperation'); //if it is relation edit $viewer->assign('IS_RELATION_OPERATION', $isRelationOperation); if ($isRelationOperation) { $viewer->assign('SOURCE_MODULE', $request->get('sourceModule')); $viewer->assign('SOURCE_RECORD', $request->get('sourceRecord')); } $viewer->assign('MAX_UPLOAD_LIMIT_MB', Vtiger_Util_Helper::getMaxUploadSize()); $viewer->assign('MAX_UPLOAD_LIMIT', vglobal('upload_maxsize')); $viewer->view('EditView.tpl', $moduleName); }
/** * Function to get the record model based on the request parameters * @param Vtiger_Request $request * @return Vtiger_Record_Model or Module specific Record Model instance */ public function getRecordModelFromRequest(Vtiger_Request $request) { $recordModel = parent::getRecordModelFromRequest($request); $startDate = $request->get('date_start'); if (!empty($startDate)) { //Start Date and Time values $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($request->get('time_start')); $startDate = Vtiger_Date_UIType::getDBInsertedValue($request->get('date_start')); if ($startTime) { $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('date_start') . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); } $recordModel->set('date_start', $startDate); $recordModel->set('time_start', $startTime); } $endDate = $request->get('due_date'); if (!empty($endDate)) { //End Date and Time values $endTime = $request->get('time_end'); $endDate = Vtiger_Date_UIType::getDBInsertedValue($request->get('due_date')); if ($endTime) { $endTime = Vtiger_Time_UIType::getTimeValueWithSeconds($endTime); $endDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('due_date') . " " . $endTime); list($endDate, $endTime) = explode(' ', $endDateTime); } $recordModel->set('time_end', $endTime); $recordModel->set('due_date', $endDate); } $record = $request->get('record'); if (!$record) { $activityType = $request->get('activitytype'); $visibility = $request->get('visibility'); if (empty($activityType)) { $recordModel->set('activitytype', 'Task'); $visibility = 'Private'; $recordModel->set('visibility', $visibility); } } if (empty($visibility)) { $assignedUserId = $recordModel->get('assigned_user_id'); $sharedType = Calendar_Module_Model::getSharedType($assignedUserId); if ($sharedType == 'selectedusers') { $sharedType = 'public'; } $recordModel->set('visibility', ucfirst($sharedType)); } return $recordModel; }
public function getRecordModelFromRequest(Vtiger_Request $request) { $moduleName = $request->getModule(); $recordId = $request->get('record'); if (!empty($recordId)) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); $recordModel->set('id', $recordId); $recordModel->set('mode', 'edit'); $fieldModelList = $recordModel->getModule()->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { //For not converting craetedtime and modified time to user format $uiType = $fieldModel->get('uitype'); if ($uiType == 70) { $fieldValue = $recordModel->get($fieldName); } else { $fieldValue = $fieldModel->getUITypeModel()->getUserRequestValue($recordModel->get($fieldName)); } if ($fieldName === $request->get('field')) { $fieldValue = $request->get('value'); } $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } $recordModel->set($fieldName, $fieldValue); } } else { $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $recordModel->set('mode', ''); $fieldModelList = $moduleModel->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { if ($request->has($fieldName)) { $fieldValue = $request->get($fieldName, null); } else { $fieldValue = $fieldModel->getDefaultFieldValue(); // to update the support_end_date and support_start_date in Quick create if ($fieldName == 'support_end_date') { $fieldValue = DateTimeField::convertToUserFormat(date('Y-m-d', strtotime("+1 year"))); } else { if ($fieldName == 'support_start_date') { $fieldValue = DateTimeField::convertToUserFormat(date('Y-m-d')); } } } $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } } } return $recordModel; }
/** * Function to save the record */ public function save() { $currentUser = Users_Record_Model::getCurrentUserModel(); $mode = $this->get('mode'); $db = PearDatabase::getInstance(); $this->setCheckBoxValue('enabled'); $this->setCheckBoxValue('captcha'); $this->setCheckBoxValue('roundrobin'); if (is_array($this->get('roundrobin_userid'))) { $roundrobinUsersList = json_encode($this->get('roundrobin_userid'), JSON_FORCE_OBJECT); } //Saving data about webform if ($mode) { $updateQuery = "UPDATE vtiger_webforms SET description = ?, returnurl = ?, ownerid = ?, enabled = ?, captcha = ? , roundrobin = ?, roundrobin_userid = ?, roundrobin_logic = ? ,targetmodule = ? WHERE id = ?"; $params = array($this->get('description'), $this->get('returnurl'), $this->get('ownerid'), $this->get('enabled'), $this->get('captcha'), $this->get('roundrobin'), $roundrobinUsersList, 0, $this->get('targetmodule'), $this->getId()); $db->pquery($updateQuery, $params); } else { $insertQuery = "INSERT INTO vtiger_webforms(name, targetmodule, publicid, enabled, description, ownerid, returnurl, captcha, roundrobin, roundrobin_userid, roundrobin_logic) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $params = array($this->getName(), $this->get('targetmodule'), $this->generatePublicId(), $this->get('enabled'), $this->get('description'), $this->get('ownerid'), $this->get('returnurl'), $this->get('captcha'), $this->get('roundrobin'), $roundrobinUsersList, 0); $db->pquery($insertQuery, $params); $this->set('id', $db->getLastInsertID()); } //Deleting existing data $db->pquery("DELETE FROM vtiger_webforms_field WHERE webformid = ?", array($this->getId())); //Saving data of source module fields info for this webform $selectedFieldsData = $this->get('selectedFieldsData'); $sourceModuleModel = Vtiger_Module_Model::getInstance($this->get('targetmodule')); $fieldInsertQuery = "INSERT INTO vtiger_webforms_field(webformid, fieldname, neutralizedfield, defaultvalue, required, sequence, hidden) VALUES(?, ?, ?, ?, ?, ?, ?)"; foreach ($selectedFieldsData as $fieldName => $fieldDetails) { $params = array($this->getId()); $neutralizedField = $fieldName; $fieldDefaultValue = $fieldDetails['defaultvalue']; $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $sourceModuleModel); $dataType = $fieldModel->getFieldDataType(); //Updating custom field label if (self::isCustomField($fieldName)) { $neutralizedField = 'label:' . str_replace(' ', '_', decode_html($fieldModel->get('label'))); } //Handling multi picklist if (is_array($fieldDefaultValue)) { $fieldDefaultValue = implode(" |##| ", $fieldDefaultValue); } //Handling Data format if ($dataType === 'date') { $fieldDefaultValue = Vtiger_Date_UIType::getDBInsertedValue($fieldDefaultValue); } if ($dataType === 'time') { $fieldDefaultValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldDefaultValue); } //Handling CheckBox value if ($dataType === 'boolean') { if ($fieldDefaultValue) { $fieldDefaultValue = 'on'; } else { $fieldDefaultValue = ''; } } if ($dataType === 'reference') { $referenceModule = $fieldDetails['referenceModule']; $referenceObject = VtigerWebserviceObject::fromName($db, $referenceModule); $referenceEntityId = $referenceObject->getEntityId(); $fieldDefaultValue = $referenceEntityId . "x" . $fieldDefaultValue; } if ($dataType === 'currency') { $decimalSeperator = $currentUser->get('currency_decimal_separator'); $groupSeperator = $currentUser->get('currency_grouping_separator'); $fieldDefaultValue = str_replace($decimalSeperator, '.', $fieldDefaultValue); $fieldDefaultValue = str_replace($groupSeperator, '', $fieldDefaultValue); } array_push($params, $fieldName, $neutralizedField, $fieldDefaultValue, $fieldDetails['required'], $fieldDetails['sequence'], $fieldDetails['hidden']); $db->pquery($fieldInsertQuery, $params); } }
/** * Function to get the record model based on the request parameters * @param Vtiger_Request $request * @return Vtiger_Record_Model or Module specific Record Model instance */ protected function getRecordModelFromRequest(Vtiger_Request $request) { $moduleName = $request->getModule(); $recordId = $request->get('record'); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); if (!empty($recordId)) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); $modelData = $recordModel->getData(); $recordModel->set('id', $recordId); $recordModel->set('mode', 'edit'); //Due to dependencies on the activity_reminder api in Activity.php(5.x) $_REQUEST['mode'] = 'edit'; } else { $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $modelData = $recordModel->getData(); $recordModel->set('mode', ''); } $fieldModelList = $moduleModel->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { $fieldValue = $request->get($fieldName, null); if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } } //Start Date and Time values $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($request->get('time_start')); $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('date_start') . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); $recordModel->set('date_start', $startDate); $recordModel->set('time_start', $startTime); //End Date and Time values $endTime = $request->get('time_end'); $endDate = Vtiger_Date_UIType::getDBInsertedValue($request->get('due_date')); if ($endTime) { $endTime = Vtiger_Time_UIType::getTimeValueWithSeconds($endTime); $endDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('due_date') . " " . $endTime); list($endDate, $endTime) = explode(' ', $endDateTime); } $recordModel->set('time_end', $endTime); $recordModel->set('due_date', $endDate); $activityType = $request->get('activitytype'); if (empty($activityType)) { $recordModel->set('activitytype', 'Task'); $recordModel->set('visibility', 'Private'); } //Due to dependencies on the older code $setReminder = $request->get('set_reminder'); if ($setReminder == 'on') { $_REQUEST['set_reminder'] = 'Yes'; } else { $_REQUEST['set_reminder'] = 'No'; } $time = strtotime($request->get('due_date')) - strtotime($request->get('date_start')); $hours = (double) $time / 3600; $minutes = ((double) $hours - (int) $hours) * 60; $recordModel->set('duration_hours', (int) $hours); $recordModel->set('duration_minutes', $minutes); return $recordModel; }
/** * Function to get the record model based on the request parameters * @param Vtiger_Request $request * @return Vtiger_Record_Model or Module specific Record Model instance */ public function getRecordModelFromRequest(Vtiger_Request $request) { $recordModel = parent::getRecordModelFromRequest($request); $startDate = $request->get('date_start'); if (!empty($startDate)) { //Start Date and Time values $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($request->get('time_start')); $startDate = Vtiger_Date_UIType::getDBInsertedValue($request->get('date_start')); if ($startTime) { $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('date_start') . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); } $recordModel->set('date_start', $startDate); $recordModel->set('time_start', $startTime); } $endDate = $request->get('due_date'); if (!empty($endDate)) { //End Date and Time values $endTime = $request->get('time_end'); $endDate = Vtiger_Date_UIType::getDBInsertedValue($request->get('due_date')); if ($endTime) { $endTime = Vtiger_Time_UIType::getTimeValueWithSeconds($endTime); $endDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('due_date') . " " . $endTime); list($endDate, $endTime) = explode(' ', $endDateTime); } $recordModel->set('time_end', $endTime); $recordModel->set('due_date', $endDate); } $record = $request->get('record'); if (!$record) { $activityType = $request->get('activitytype'); $visibility = $request->get('visibility'); if (empty($activityType)) { $recordModel->set('activitytype', 'Task'); $visibility = 'Private'; $recordModel->set('visibility', $visibility); } } if (empty($visibility)) { $assignedUserId = $recordModel->get('assigned_user_id'); $sharedType = Calendar_Module_Model::getSharedType($assignedUserId); if ($sharedType == 'selectedusers') { $sharedType = 'public'; } $recordModel->set('visibility', ucfirst($sharedType)); } $time = strtotime($endTime) - strtotime($startTime); $diffinSec = strtotime($endDate) - strtotime($startDate); $diff_days = floor($diffinSec / (60 * 60 * 24)); $hours = (double) $time / 3600 + $diff_days * 24; $minutes = ((double) $hours - (int) $hours) * 60; $recordModel->set('duration_hours', (int) $hours); $recordModel->set('duration_minutes', round($minutes, 0)); return $recordModel; }
/** * Function to save the record */ public function save() { $mode = $this->get('mode'); $db = PearDatabase::getInstance(); if ($this->get('enabled') == "on") { $this->set('enabled', 1); } else { $this->set('enabled', 0); } //Saving data about webform if ($mode) { $updateQuery = "UPDATE vtiger_webforms SET description = ?, returnurl = ?, ownerid = ?, enabled = ? WHERE id = ?"; $params = array($this->get('description'), $this->get('returnurl'), $this->get('ownerid'), $this->get('enabled'), $this->getId()); $db->pquery($updateQuery, $params); } else { $insertQuery = "INSERT INTO vtiger_webforms(name, targetmodule, publicid, enabled, description, ownerid, returnurl) VALUES(?, ?, ?, ?, ?, ?, ?)"; $params = array($this->getName(), $this->get('targetmodule'), $this->generatePublicId(), $this->get('enabled'), $this->get('description'), $this->get('ownerid'), $this->get('returnurl')); $db->pquery($insertQuery, $params); $this->set('id', $db->getLastInsertID()); } //Deleting existing data $db->pquery("DELETE FROM vtiger_webforms_field WHERE webformid = ?", array($this->getId())); //Saving data of source module fields info for this webform $selectedFieldsData = $this->get('selectedFieldsData'); $sourceModuleModel = Vtiger_Module_Model::getInstance($this->get('targetmodule')); $fieldInsertQuery = "INSERT INTO vtiger_webforms_field(webformid, fieldname, neutralizedfield, defaultvalue, required) VALUES(?, ?, ?, ?, ?)"; foreach ($selectedFieldsData as $fieldName => $fieldDetails) { $params = array($this->getId()); $neutralizedField = $fieldName; $fieldDefaultValue = $fieldDetails['defaultvalue']; $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $sourceModuleModel); $dataType = $fieldModel->getFieldDataType(); //Updating custom field label if (self::isCustomField($fieldName)) { $neutralizedField = 'label:' . str_replace(' ', '_', decode_html($fieldModel->get('label'))); } //Handling multi picklist if (is_array($fieldDefaultValue)) { $fieldDefaultValue = implode(" |##| ", $fieldDefaultValue); } //Handling Data format if ($dataType === 'date') { $fieldDefaultValue = Vtiger_Date_UIType::getDBInsertedValue($fieldDefaultValue); } if ($dataType === 'time') { $fieldDefaultValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldDefaultValue); } //Handling CheckBox value if ($dataType === 'boolean') { if ($fieldDefaultValue) { $fieldDefaultValue = 'on'; } else { $fieldDefaultValue = ''; } } array_push($params, $fieldName, $neutralizedField, $fieldDefaultValue, $fieldDetails['required']); $db->pquery($fieldInsertQuery, $params); } }
public static function transferListSearchParamsToFilterCondition($listSearchParams, $moduleModel) { if(empty($listSearchParams)) { $listSearchParams = array(); } $advFilterConditionFormat = array(); $glueOrder = array('and','or'); $groupIterator = 0; foreach($listSearchParams as $groupInfo){ if(empty($groupInfo)){ continue; } $groupConditionInfo = array(); $groupColumnsInfo = array(); $groupConditionGlue = $glueOrder[$groupIterator]; foreach($groupInfo as $fieldSearchInfo){ $advFilterFieldInfoFormat = array(); $fieldName = $fieldSearchInfo[0]; $operator = $fieldSearchInfo[1]; $fieldValue = $fieldSearchInfo[2]; $fieldInfo = $moduleModel->getField($fieldName); //Request will be having in terms of AM and PM but the database will be having in 24 hr format so converting //Database format if($fieldInfo->getFieldDataType() == "time") { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if($fieldName == 'amount' && $fieldInfo->getFieldDataType() == 'currency'){ $fieldValue = CurrencyField::convertToDBFormat($fieldValue); } if($fieldName == 'date_start' || $fieldName == 'due_date' || $fieldInfo->getFieldDataType() == "datetime" ) { $dateValues = explode(',', $fieldValue); //Indicate whether it is fist date in the between condition $isFirstDate = true; foreach($dateValues as $key => $dateValue) { $dateTimeCompoenents = explode(' ', $dateValue); if(empty($dateTimeCompoenents[1])) { if($isFirstDate) $dateTimeCompoenents[1] = '00:00:00'; else $dateTimeCompoenents[1] = '23:59:59'; } $dateValue = implode(' ',$dateTimeCompoenents); $dateValues[$key] = $dateValue; $isFirstDate = false; } $fieldValue = implode(',',$dateValues); } $advFilterFieldInfoFormat['columnname'] = $fieldInfo->getCustomViewColumnName(); $advFilterFieldInfoFormat['comparator'] = $operator; $advFilterFieldInfoFormat['value'] = $fieldValue; $advFilterFieldInfoFormat['column_condition'] = $groupConditionGlue; $groupColumnsInfo[] = $advFilterFieldInfoFormat; } $noOfConditions = count($groupColumnsInfo); //to remove the last column condition $groupColumnsInfo[$noOfConditions-1]['column_condition'] = ''; $groupConditionInfo['columns'] = $groupColumnsInfo; $groupConditionInfo['condition'] = 'and'; $advFilterConditionFormat[] = $groupConditionInfo; $groupIterator++; } //We aer removing last condition since this condition if there is next group and this is the last group unset($advFilterConditionFormat[count($advFilterConditionFormat)-1]['condition']); return $advFilterConditionFormat; }
public function process(Vtiger_Request $request) { $adb = PearDatabase::getInstance(); $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $record = $request->get('record'); if (!empty($record) && $request->get('isDuplicate') == true) { $recordModel = $this->record ? $this->record : Vtiger_Record_Model::getInstanceById($record, $moduleName); $viewer->assign('MODE', ''); } else { if (!empty($record)) { $recordModel = $this->record ? $this->record : Vtiger_Record_Model::getInstanceById($record, $moduleName); $viewer->assign('RECORD_ID', $record); $viewer->assign('MODE', 'edit'); } else { $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $viewer->assign('MODE', ''); } } if (!$this->record) { $this->record = $recordModel; } $moduleModel = $recordModel->getModule(); $fieldList = $moduleModel->getFields(); $requestFieldList = array_intersect_key($request->getAll(), $fieldList); foreach ($requestFieldList as $fieldName => $fieldValue) { $fieldModel = $fieldList[$fieldName]; $specialField = false; // We collate date and time part together in the EditView UI handling // so a bit of special treatment is required if we come from QuickCreate if ($moduleName == 'Calendar' && empty($record) && $fieldName == 'time_start' && !empty($fieldValue)) { $specialField = true; // Convert the incoming user-picked time to GMT time // which will get re-translated based on user-time zone on EditForm $fieldValue = DateTimeField::convertToDBTimeZone($fieldValue)->format("H:i"); } if ($moduleName == 'Calendar' && empty($record) && $fieldName == 'date_start' && !empty($fieldValue)) { $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($requestFieldList['time_start']); $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($fieldValue . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); $fieldValue = Vtiger_Date_UIType::getDisplayDateValue($startDate); } if ($fieldModel->isEditable() || $specialField) { $recordModel->set($fieldName, $fieldModel->getDBInsertValue($fieldValue)); } } $recordStructureInstance = Vtiger_RecordStructure_Model::getInstanceFromRecordModel($recordModel, Vtiger_RecordStructure_Model::RECORD_STRUCTURE_MODE_EDIT); $picklistDependencyDatasource = Vtiger_DependencyPicklist::getPicklistDependencyDatasource($moduleName); $viewer->assign('PICKIST_DEPENDENCY_DATASOURCE', Zend_Json::encode($picklistDependencyDatasource)); $mappingRelatedField = $moduleModel->getMappingRelatedField($moduleName); $viewer->assign('MAPPING_RELATED_FIELD', Zend_Json::encode($mappingRelatedField)); $viewer->assign('RECORD_STRUCTURE_MODEL', $recordStructureInstance); $viewer->assign('RECORD_STRUCTURE', $recordStructureInstance->getStructure()); $viewer->assign('MODULE', $moduleName); $viewer->assign('BLOCK_LIST', $moduleModel->getBlocks()); $viewer->assign('CURRENTDATE', date('Y-n-j')); $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel()); $viewer->assign('RECORD_MODEL', $recordModel); $isRelationOperation = $request->get('relationOperation'); //if it is relation edit $viewer->assign('IS_RELATION_OPERATION', $isRelationOperation); if ($isRelationOperation) { $viewer->assign('SOURCE_MODULE', $request->get('sourceModule')); $viewer->assign('SOURCE_RECORD', $request->get('sourceRecord')); } $viewer->assign('MAX_UPLOAD_LIMIT_MB', vglobal('upload_maxsize') / 1000000); $viewer->assign('MAX_UPLOAD_LIMIT', vglobal('upload_maxsize')); // check if passwords are encrypted if (file_exists('modules/OSSPasswords/config.ini')) { // encryption key exists so passwords are encrypted $config = parse_ini_file('modules/OSSPasswords/config.ini'); // let smarty know that passwords are encrypted $viewer->assign('ENCRYPTED', true); $viewer->assign('ENC_KEY', $config['key']); $viewer->assign('RECORD', $_GET['record']); $viewer->assign('VIEW', $_GET['view']); } else { $viewer->assign('ENCRYPTED', false); $viewer->assign('ENC_KEY', ''); $viewer->assign('RECORD', $_GET['record']); $viewer->assign('VIEW', $_GET['view']); } // widget button // get min, max, allow_chars from vtiger_passwords_config $result = $adb->query("SELECT * FROM vtiger_passwords_config WHERE 1 LIMIT 1", true); $min = $adb->query_result($result, 0, 'pass_length_min'); $max = $adb->query_result($result, 0, 'pass_length_max'); $allow_chars = $adb->query_result($result, 0, 'pass_allow_chars'); $GenerateButton = 'Generate Password'; $ConfigureButton = 'LBL_ConfigurePass'; $viewer = $this->getViewer($request); $viewer->assign('GENERATEPASS', $GenerateButton); $viewer->assign('GENERATEONCLICK', 'generate_password(' . $min . ',' . $max . ',\'' . $allow_chars . '\');'); $viewer->view('EditView.tpl', $moduleName); }
function save() { //Time should changed to 24hrs format $_REQUEST['time_start'] = Vtiger_Time_UIType::getTimeValueWithSeconds($_REQUEST['time_start']); $_REQUEST['time_end'] = Vtiger_Time_UIType::getTimeValueWithSeconds($_REQUEST['time_end']); parent::save(); }
public function process(Vtiger_Request $request) { $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $record = $request->get('record'); if (!empty($record) && $request->get('isDuplicate') == true) { $recordModel = $this->record ? $this->record : Vtiger_Record_Model::getInstanceById($record, $moduleName); $viewer->assign('MODE', ''); //While Duplicating record, If the related record is deleted then we are removing related record info in record model $mandatoryFieldModels = $recordModel->getModule()->getMandatoryFieldModels(); foreach ($mandatoryFieldModels as $fieldModel) { if ($fieldModel->isReferenceField()) { $fieldName = $fieldModel->get('name'); if (Vtiger_Util_Helper::checkRecordExistance($recordModel->get($fieldName))) { $recordModel->set($fieldName, ''); } } } } else { if (!empty($record)) { $recordModel = $this->record ? $this->record : Vtiger_Record_Model::getInstanceById($record, $moduleName); $viewer->assign('RECORD_ID', $record); $viewer->assign('MODE', 'edit'); } else { $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $viewer->assign('MODE', ''); } } if (!$this->record) { $this->record = $recordModel; } $moduleModel = $recordModel->getModule(); $fieldList = $moduleModel->getFields(); $requestFieldList = array_intersect_key($request->getAll(), $fieldList); foreach ($requestFieldList as $fieldName => $fieldValue) { $fieldModel = $fieldList[$fieldName]; $specialField = false; // We collate date and time part together in the EditView UI handling // so a bit of special treatment is required if we come from QuickCreate if ($moduleName == 'Calendar' && empty($record) && $fieldName == 'time_start' && !empty($fieldValue)) { $specialField = true; // Convert the incoming user-picked time to GMT time // which will get re-translated based on user-time zone on EditForm $fieldValue = DateTimeField::convertToDBTimeZone($fieldValue)->format("H:i"); } if ($moduleName == 'Calendar' && empty($record) && $fieldName == 'date_start' && !empty($fieldValue)) { $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($requestFieldList['time_start']); $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($fieldValue . " " . $startTime); list($startDate, $startTime) = explode(' ', $startDateTime); $fieldValue = Vtiger_Date_UIType::getDisplayDateValue($startDate); } if ($fieldModel->isEditable() || $specialField) { $recordModel->set($fieldName, $fieldModel->getDBInsertValue($fieldValue)); } } // SalesPlatform.ru begin Unifying method for EditView preparing $recordModel = prepareEditView($recordModel, $_REQUEST, $viewer); // SalesPlatform.ru end // SalesPlatform.ru begin Set company if ($request->get('relationOperation')) { $sourceRecordModel = Vtiger_Record_Model::getInstanceById($request->get('sourceRecord')); if ($sourceRecordModel->get('spcompany') != null && $sourceRecordModel->get('spcompany') != '') { if ($recordModel->getField('spcompany')) { $recordModel->set('spcompany', $sourceRecordModel->get('spcompany')); } } } // SalesPlatform.ru end $recordStructureInstance = Vtiger_RecordStructure_Model::getInstanceFromRecordModel($recordModel, Vtiger_RecordStructure_Model::RECORD_STRUCTURE_MODE_EDIT); $picklistDependencyDatasource = Vtiger_DependencyPicklist::getPicklistDependencyDatasource($moduleName); // SalesPlatform.ru begin Field Validation Information $tabid = getTabid($moduleName); $validationData = getDBValidationData($recordModel->get('tab_name'), $tabid); $validationArray = split_validationdataArray($validationData); $viewer->assign("VALIDATION_DATA_FIELDNAME", $validationArray['fieldname']); $viewer->assign("VALIDATION_DATA_FIELDDATATYPE", $validationArray['datatype']); $viewer->assign("VALIDATION_DATA_FIELDLABEL", $validationArray['fieldlabel']); $viewer->assign('ID', $record); // SalesPlatform.ru end $viewer->assign('PICKIST_DEPENDENCY_DATASOURCE', Zend_Json::encode($picklistDependencyDatasource)); $viewer->assign('RECORD_STRUCTURE_MODEL', $recordStructureInstance); $viewer->assign('RECORD_STRUCTURE', $recordStructureInstance->getStructure()); $viewer->assign('MODULE', $moduleName); $viewer->assign('CURRENTDATE', date('Y-n-j')); $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel()); $isRelationOperation = $request->get('relationOperation'); //if it is relation edit $viewer->assign('IS_RELATION_OPERATION', $isRelationOperation); if ($isRelationOperation) { $viewer->assign('SOURCE_MODULE', $request->get('sourceModule')); $viewer->assign('SOURCE_RECORD', $request->get('sourceRecord')); } $viewer->assign('MAX_UPLOAD_LIMIT_MB', Vtiger_Util_Helper::getMaxUploadSize()); $viewer->assign('MAX_UPLOAD_LIMIT', vglobal('upload_maxsize')); // SalesPlatform.ru begin enable/disable button Import $instance = Vtiger_Module::getInstance('SPSocialConnector'); $fl_import_button = true; if (empty($record) || $instance->presence == 1) { $fl_import_button = false; } $viewer->assign("FL_IMPORT_BUTTON", $fl_import_button); // SalesPlatform.ru end $viewer->view('EditView.tpl', $moduleName); }
/** * Function to get the record model based on the request parameters * @param Vtiger_Request $request * @return Vtiger_Record_Model or Module specific Record Model instance */ public function getRecordModelFromRequest(Vtiger_Request $request) { $moduleName = $request->getModule(); $recordId = $request->get('record'); if (!empty($recordId)) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); $recordModel->set('id', $recordId); $recordModel->set('mode', 'edit'); $fieldModelList = $recordModel->getModule()->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { //For not converting craetedtime and modified time to user format $uiType = $fieldModel->get('uitype'); if ($uiType == 70) { $fieldValue = $recordModel->get($fieldName); } elseif (in_array($uiType, [71, 72])) { // currency ui types $fieldValue = $recordModel->get($fieldName); $fieldValue = CurrencyField::convertToUserFormat($fieldValue, null, true); } else { $fieldValue = $fieldModel->getUITypeModel()->getUserRequestValue($recordModel->get($fieldName), $recordId); } if ($fieldName === $request->get('field')) { $fieldValue = $request->get('value'); } $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } $recordModel->set($fieldName, $fieldValue); } } else { $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $recordModel->set('mode', ''); $fieldModelList = $moduleModel->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { if ($request->has($fieldName)) { $fieldValue = $request->get($fieldName, null); } else { $fieldValue = $fieldModel->getDefaultFieldValue(); } $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } } } return $recordModel; }
/** * Function to get the record model based on the request parameters * @param Vtiger_Request $request * @return Vtiger_Record_Model or Module specific Record Model instance */ public function getRecordModelFromRequest(Vtiger_Request $request) { global $log; $log->debug("Entering ./actions/SaveAjax.php::getRecordModelFromRequest"); $moduleName = $request->getModule(); $recordId = $request->get('record'); if (!empty($recordId)) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); $recordModel->set('id', $recordId); $recordModel->set('mode', 'edit'); $fieldModelList = $recordModel->getModule()->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { //For not converting craetedtime and modified time to user format $uiType = $fieldModel->get('uitype'); if ($uiType == 70) { $fieldValue = $recordModel->get($fieldName); } else { $fieldValue = $fieldModel->getUITypeModel()->getUserRequestValue($recordModel->get($fieldName)); } if ($fieldName === $request->get('field')) { $fieldValue = $request->get('value'); } $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } $recordModel->set($fieldName, $fieldValue); } } else { $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $recordModel->set('mode', ''); $fieldModelList = $moduleModel->getFields(); foreach ($fieldModelList as $fieldName => $fieldModel) { if ($request->has($fieldName)) { $fieldValue = $request->get($fieldName, null); } else { $fieldValue = $fieldModel->getDefaultFieldValue(); } $fieldDataType = $fieldModel->getFieldDataType(); if ($fieldDataType == 'time') { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if ($fieldValue !== null) { if (!is_array($fieldValue)) { $fieldValue = trim($fieldValue); } $recordModel->set($fieldName, $fieldValue); } } } return $recordModel; }