public function create($elementType, $element)
 {
     global $adb, $log;
     $crmObject = new VtigerCRMObject($elementType, false);
     if ($element['filelocationtype'] == 'I' and !empty($element['filename'])) {
         $file = $element['filename'];
         $element['filesize'] = $file['size'];
         $file['assigned_user_id'] = $element['assigned_user_id'];
         $file['setype'] = "Documents Attachment";
         $attachid = SaveAttachmentDB($file);
         $element['filetype'] = $file['type'];
         $element['filename'] = $filename = str_replace(array(' ', '/'), '_', $file['name']);
         // no spaces nor slashes
     }
     $element = DataTransform::sanitizeForInsert($element, $this->meta);
     $error = $crmObject->create($element);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
     }
     $id = $crmObject->getObjectId();
     $error = $crmObject->read($id);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
     }
     if ($element['filelocationtype'] == 'I' and !empty($attachid)) {
         // Link file attached to document
         $adb->pquery("INSERT INTO vtiger_seattachmentsrel(crmid, attachmentsid) VALUES(?,?)", array($id, $attachid));
     }
     // Establish relations *** this is done by the main vtws_create() function  ***
     return DataTransform::filterAndSanitize($crmObject->getFields(), $this->meta);
 }
Ejemplo n.º 2
0
 public function create($elementType, $element)
 {
     global $adb, $log;
     $crmObject = new VtigerCRMObject($elementType, false);
     $attachments = array();
     if (!empty($element['files'])) {
         foreach ($element['files'] as $file) {
             $element['filesize'] = $file['size'];
             $file['assigned_user_id'] = $element['assigned_user_id'];
             $file['setype'] = "Emails Attachment";
             $attachments[] = SaveAttachmentDB($file);
             $element['filetype'] = $file['type'];
             $element['filename'] = $filename = str_replace(' ', '_', $file['name']);
         }
     }
     $_REQUEST['module'] = 'Emails';
     $element = DataTransform::sanitizeForInsert($element, $this->meta);
     $relations = $element['related'];
     if (!empty($relations) and is_array($relations)) {
         $_REQUEST['parent_id'] = '';
         foreach ($relations as $rel) {
             $ids = vtws_getIdComponents($rel);
             $relid = $ids[1];
             if (!empty($relid)) {
                 $tabname = $adb->query_result($adb->pquery('select name from vtiger_ws_entity where id=?', array($ids[0])), 0, 'name');
                 $tabid = getTabid($tabname);
                 $fieldid = $adb->query_result($adb->pquery('select fieldid from vtiger_field where tabid=? and uitype=13 and vtiger_field.presence in (0,2)', array($tabid)), 0, 'fieldid');
                 $_REQUEST['parent_id'] .= $relid . '@' . $fieldid . '|';
             }
         }
     } else {
         $_REQUEST['parent_id'] = $element['parent_id'];
     }
     $error = $crmObject->create($element);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
     }
     $id = $crmObject->getObjectId();
     $error = $crmObject->read($id);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachid) {
             // Link file attached to document
             $adb->pquery("INSERT INTO vtiger_seattachmentsrel(crmid, attachmentsid) VALUES(?,?)", array($id, $attachid));
         }
     }
     return DataTransform::filterAndSanitize($crmObject->getFields(), $this->meta);
 }
Ejemplo n.º 3
0
 public function create($elementType, $element)
 {
     $crmObject = new VtigerCRMObject($elementType, false);
     $element = DataTransform::sanitizeForInsert($element, $this->meta);
     $error = $crmObject->create($element);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
     }
     $id = $crmObject->getObjectId();
     $error = $crmObject->read($id);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
     }
     return DataTransform::filterAndSanitize($crmObject->getFields(), $this->meta);
 }
 public function create($elementType, $element)
 {
     $crmObject = new VtigerCRMObject($elementType, false);
     $element = DataTransform::sanitizeForInsert($element, $this->meta);
     $error = $crmObject->create($element);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$DATABASEQUERYERROR));
     }
     $id = $crmObject->getObjectId();
     $error = $crmObject->read($id);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$DATABASEQUERYERROR));
     }
     return DataTransform::filterAndSanitize($crmObject->getFields(), $this->meta);
 }
 public function create($elementType, $element)
 {
     $crmObject = new VtigerCRMObject($elementType, false);
     $element = DataTransform::sanitizeForInsert($element, $this->meta);
     $error = $crmObject->create($element);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$DATABASEQUERYERROR));
     }
     $id = $crmObject->getObjectId();
     // Bulk Save Mode
     if (CRMEntity::isBulkSaveMode()) {
         // Avoiding complete read, as during bulk save mode, $result['id'] is enough
         return array('id' => vtws_getId($this->meta->getEntityId(), $id));
     }
     $error = $crmObject->read($id);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$DATABASEQUERYERROR));
     }
     return DataTransform::filterAndSanitize($crmObject->getFields(), $this->meta);
 }