コード例 #1
0
ファイル: Retrieve.php プロジェクト: Bergdahls/YetiForceCRM
function vtws_retrieve($id, $user)
{
    $adb = PearDatabase::getInstance();
    $log = vglobal('log');
    $webserviceObject = VtigerWebserviceObject::fromId($adb, $id);
    $handlerPath = $webserviceObject->getHandlerPath();
    $handlerClass = $webserviceObject->getHandlerClass();
    require_once $handlerPath;
    $handler = new $handlerClass($webserviceObject, $user, $adb, $log);
    $meta = $handler->getMeta();
    $entityName = $meta->getObjectEntityName($id);
    $types = vtws_listtypes(null, $user);
    if (!in_array($entityName, $types['types'])) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to perform the operation is denied");
    }
    if ($meta->hasReadAccess() !== true) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to write is denied");
    }
    if ($entityName !== $webserviceObject->getEntityName()) {
        throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Id specified is incorrect");
    }
    if (!$meta->hasPermission(EntityMeta::$RETRIEVE, $id)) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to read given object is denied");
    }
    $idComponents = vtws_getIdComponents($id);
    if (!$meta->exists($idComponents[1])) {
        throw new WebServiceException(WebServiceErrorCode::$RECORDNOTFOUND, "Record you are trying to access is not found");
    }
    $entity = $handler->retrieve($id);
    VTWS_PreserveGlobal::flush();
    return $entity;
}
コード例 #2
0
 public function process(Vtiger_Request $request)
 {
     $recordId = $request->get('record');
     $modules = $request->get('modules');
     $assignId = $request->get('assigned_user_id');
     $currentUser = Users_Record_Model::getCurrentUserModel();
     $entityValues = array();
     $entityValues['transferRelatedRecordsTo'] = $request->get('transferModule');
     //■権限なぜか、エラーになるので権限を固定するinouchi
     //$entityValues['assignedTo'] = vtws_getWebserviceEntityId(vtws_getOwnerType($assignId), $assignId);
     $entityValues['assignedTo'] = vtws_getWebserviceEntityId(vtws_getOwnerType(1), 1);
     $entityValues['leadId'] = vtws_getWebserviceEntityId($request->getModule(), $recordId);
     $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $request->getModule());
     $convertLeadFields = $recordModel->getConvertLeadFields();
     $availableModules = array('Accounts', 'Contacts', 'Potentials');
     foreach ($availableModules as $module) {
         if (vtlib_isModuleActive($module) && in_array($module, $modules)) {
             $entityValues['entities'][$module]['create'] = true;
             $entityValues['entities'][$module]['name'] = $module;
             foreach ($convertLeadFields[$module] as $fieldModel) {
                 $fieldName = $fieldModel->getName();
                 $fieldValue = $request->get($fieldName);
                 //Potential Amount Field value converting into DB format
                 if ($fieldModel->getFieldDataType() === 'currency') {
                     $fieldValue = Vtiger_Currency_UIType::convertToDBFormat($fieldValue);
                 } elseif ($fieldModel->getFieldDataType() === 'date') {
                     $fieldValue = DateTimeField::convertToDBFormat($fieldValue);
                 } elseif ($fieldModel->getFieldDataType() === 'reference' && $fieldValue) {
                     $ids = vtws_getIdComponents($fieldValue);
                     if (count($ids) === 1) {
                         $fieldValue = vtws_getWebserviceEntityId(getSalesEntityType($fieldValue), $fieldValue);
                     }
                 }
                 $entityValues['entities'][$module][$fieldName] = $fieldValue;
             }
         }
     }
     try {
         $result = vtws_convertlead($entityValues, $currentUser);
     } catch (Exception $e) {
         $this->showError($request, $e);
         exit;
     }
     if (!empty($result['Accounts'])) {
         $accountIdComponents = vtws_getIdComponents($result['Accounts']);
         $accountId = $accountIdComponents[1];
     }
     if (!empty($result['Contacts'])) {
         $contactIdComponents = vtws_getIdComponents($result['Contacts']);
         $contactId = $contactIdComponents[1];
     }
     if (!empty($accountId)) {
         header("Location: index.php?view=Detail&module=Accounts&record={$accountId}");
     } elseif (!empty($contactId)) {
         header("Location: index.php?view=Detail&module=Contacts&record={$contactId}");
     } else {
         $this->showError($request);
         exit;
     }
 }
コード例 #3
0
/**
 *
 * @param WebserviceId $id
 * @param String $oldPassword
 * @param String $newPassword
 * @param String $confirmPassword
 * @param Users $user 
 * 
 */
function vtws_changePassword($id, $oldPassword, $newPassword, $confirmPassword, $user)
{
    vtws_preserveGlobal('current_user', $user);
    $idComponents = vtws_getIdComponents($id);
    if ($idComponents[1] == $user->id || is_admin($user)) {
        $newUser = new Users();
        $newUser->retrieve_entity_info($idComponents[1], 'Users');
        if (!is_admin($user)) {
            if (empty($oldPassword)) {
                throw new WebServiceException(WebServiceErrorCode::$INVALIDOLDPASSWORD, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$INVALIDOLDPASSWORD));
            }
            if (!$user->verifyPassword($oldPassword)) {
                throw new WebServiceException(WebServiceErrorCode::$INVALIDOLDPASSWORD, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$INVALIDOLDPASSWORD));
            }
        }
        if (strcmp($newPassword, $confirmPassword) === 0) {
            $success = $newUser->change_password($oldPassword, $newPassword);
            $error = $newUser->db->hasFailedTransaction();
            if ($error) {
                throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$DATABASEQUERYERROR));
            }
            if (!$success) {
                throw new WebServiceException(WebServiceErrorCode::$CHANGEPASSWORDFAILURE, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$CHANGEPASSWORDFAILURE));
            }
        } else {
            throw new WebServiceException(WebServiceErrorCode::$CHANGEPASSWORDFAILURE, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$CHANGEPASSWORDFAILURE));
        }
        VTWS_PreserveGlobal::flush();
        return array('message' => 'Changed password successfully');
    }
}
コード例 #4
0
ファイル: Update.php プロジェクト: hardikk/HNH
function vtws_update($element, $user)
{
    global $log, $adb;
    $idList = vtws_getIdComponents($element['id']);
    $webserviceObject = VtigerWebserviceObject::fromId($adb, $idList[0]);
    $handlerPath = $webserviceObject->getHandlerPath();
    $handlerClass = $webserviceObject->getHandlerClass();
    require_once $handlerPath;
    $handler = new $handlerClass($webserviceObject, $user, $adb, $log);
    $meta = $handler->getMeta();
    $entityName = $meta->getObjectEntityName($element['id']);
    $types = vtws_listtypes($user);
    if (!in_array($entityName, $types['types'])) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to perform the operation is denied");
    }
    if ($entityName !== $webserviceObject->getEntityName()) {
        throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Id specified is incorrect");
    }
    if (!$meta->hasPermission(EntityMeta::$UPDATE, $element['id'])) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to read given object is denied");
    }
    if (!$meta->exists($idList[1])) {
        throw new WebServiceException(WebServiceErrorCode::$RECORDNOTFOUND, "Record you are trying to access is not found");
    }
    if ($meta->hasWriteAccess() !== true) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to write is denied");
    }
    $referenceFields = $meta->getReferenceFieldDetails();
    foreach ($referenceFields as $fieldName => $details) {
        if (isset($element[$fieldName]) && strlen($element[$fieldName]) > 0) {
            $ids = vtws_getIdComponents($element[$fieldName]);
            $elemTypeId = $ids[0];
            $elemId = $ids[1];
            $referenceObject = VtigerWebserviceObject::fromId($adb, $elemTypeId);
            if (!in_array($referenceObject->getEntityName(), $details)) {
                throw new WebServiceException(WebServiceErrorCode::$REFERENCEINVALID, "Invalid reference specified for {$fieldName}");
            }
            if (!in_array($referenceObject->getEntityName(), $types['types'])) {
                throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to access reference type is denied " . $referenceObject->getEntityName());
            }
        } else {
            if ($element[$fieldName] !== NULL) {
                unset($element[$fieldName]);
            }
        }
    }
    $meta->hasMandatoryFields($element);
    $ownerFields = $meta->getOwnerFields();
    if (is_array($ownerFields) && sizeof($ownerFields) > 0) {
        foreach ($ownerFields as $ownerField) {
            if (isset($element[$ownerField]) && $element[$ownerField] !== null && !$meta->hasAssignPrivilege($element[$ownerField])) {
                throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Cannot assign record to the given user");
            }
        }
    }
    $entity = $handler->update($element);
    VTWS_PreserveGlobal::flush();
    return $entity;
}
コード例 #5
0
ファイル: Retrieve.php プロジェクト: casati-dolibarr/corebos
function vtws_retrieve($id, $user)
{
    global $log, $adb;
    $webserviceObject = VtigerWebserviceObject::fromId($adb, $id);
    $handlerPath = $webserviceObject->getHandlerPath();
    $handlerClass = $webserviceObject->getHandlerClass();
    require_once $handlerPath;
    $handler = new $handlerClass($webserviceObject, $user, $adb, $log);
    $meta = $handler->getMeta();
    $entityName = $meta->getObjectEntityName($id);
    $types = vtws_listtypes(null, $user);
    if (!in_array($entityName, $types['types'])) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to perform the operation is denied");
    }
    if ($meta->hasReadAccess() !== true) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to write is denied");
    }
    if ($entityName !== $webserviceObject->getEntityName()) {
        throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Id specified is incorrect");
    }
    if (!$meta->hasPermission(EntityMeta::$RETRIEVE, $id)) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to read given object is denied");
    }
    $idComponents = vtws_getIdComponents($id);
    if (!$meta->exists($idComponents[1])) {
        throw new WebServiceException(WebServiceErrorCode::$RECORDNOTFOUND, "Record you are trying to access is not found");
    }
    $entity = $handler->retrieve($id);
    //return product lines
    if ($entityName == 'Quotes' || $entityName == 'PurchaseOrder' || $entityName == 'SalesOrder' || $entityName == 'Invoice') {
        list($wsid, $recordid) = explode('x', $id);
        $result = $adb->pquery('select * from vtiger_inventoryproductrel where id=?', array($recordid));
        while ($row = $adb->getNextRow($result, false)) {
            if ($row['discount_amount'] == NULL && $row['discount_percent'] == NULL) {
                $discount = 0;
                $discount_type = 0;
            } else {
                $discount = 1;
            }
            if ($row['discount_amount'] == NULL) {
                $discount_amount = 0;
            } else {
                $discount_amount = $row['discount_amount'];
                $discount_type = 'amount';
            }
            if ($row['discount_percent'] == NULL) {
                $discount_percent = 0;
            } else {
                $discount_percent = $row['discount_percent'];
                $discount_type = 'percentage';
            }
            $onlyPrd = array("productid" => $row['productid'], "comment" => $row['comment'], "qty" => $row['quantity'], "listprice" => $row['listprice'], 'discount' => $discount, "discount_type" => $discount_type, "discount_percentage" => $discount_percent, "discount_amount" => $discount_amount);
            $entity['pdoInformation'][] = $onlyPrd;
        }
    }
    VTWS_PreserveGlobal::flush();
    return $entity;
}
コード例 #6
0
function vtws_retrievedocattachment($all_ids, $returnfile, $user)
{
    global $log, $adb;
    $entities = array();
    $docWSId = vtyiicpng_getWSEntityId('Documents');
    $log->debug("Entering function vtws_retrievedocattachment");
    $all_ids = "(" . str_replace($docWSId, '', $all_ids) . ")";
    $query = "SELECT n.notesid, n.filename, n.filelocationtype\n                  FROM vtiger_notes n\n                  INNER JOIN vtiger_crmentity c ON c.crmid=n.notesid\n                  WHERE n.notesid in {$all_ids} and n.filelocationtype in ('I','E') and c.deleted=0";
    $result = $adb->query($query);
    $nr = $adb->num_rows($result);
    for ($i = 0; $i < $nr; $i++) {
        $id = $docWSId . $adb->query_result($result, $i, 'notesid');
        $webserviceObject = VtigerWebserviceObject::fromId($adb, $id);
        $handlerPath = $webserviceObject->getHandlerPath();
        $handlerClass = $webserviceObject->getHandlerClass();
        require_once $handlerPath;
        $handler = new $handlerClass($webserviceObject, $user, $adb, $log);
        $meta = $handler->getMeta();
        $entityName = $meta->getObjectEntityName($id);
        $types = vtws_listtypes(null, $user);
        if (!in_array($entityName, $types['types'])) {
            throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to perform the operation is denied");
        }
        if ($meta->hasReadAccess() !== true) {
            throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to write is denied");
        }
        if ($entityName !== $webserviceObject->getEntityName()) {
            throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Id specified is incorrect");
        }
        if (!$meta->hasPermission(EntityMeta::$RETRIEVE, $id)) {
            throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to read given object ({$id}) is denied");
        }
        $ids = vtws_getIdComponents($id);
        if (!$meta->exists($ids[1])) {
            throw new WebServiceException(WebServiceErrorCode::$RECORDNOTFOUND, "Document Record you are trying to access is not found");
        }
        $document_id = $ids[1];
        $filetype = $adb->query_result($result, $i, 'filelocationtype');
        if ($filetype == 'E') {
            $entity["recordid"] = $adb->query_result($result, $i, 'notesid');
            $entity["filetype"] = $fileType;
            $entity["filename"] = $adb->query_result($result, $i, 'filename');
            $entity["filesize"] = 0;
            $entity["attachment"] = base64_encode('');
        } elseif ($filetype == 'I') {
            $entity = vtws_retrievedocattachment_get_attachment($document_id, true, $returnfile);
        }
        $entities[$id] = $entity;
        VTWS_PreserveGlobal::flush();
    }
    // end for ids
    $log->debug("Leaving function vtws_retrievedocattachment");
    return $entities;
}
コード例 #7
0
ファイル: VtigerModuleOperation.php プロジェクト: hardikk/HNH
 public function delete($id)
 {
     $ids = vtws_getIdComponents($id);
     $elemid = $ids[1];
     $crmObject = new VtigerCRMObject($this->tabId, true);
     $error = $crmObject->delete($elemid);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
     }
     return array("status" => "successful");
 }
コード例 #8
0
 public function delete($id)
 {
     $ids = vtws_getIdComponents($id);
     $elemid = $ids[1];
     $crmObject = new VtigerCRMObject($this->tabId, true);
     $error = $crmObject->delete($elemid);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$DATABASEQUERYERROR));
     }
     return array("status" => "successful");
 }
コード例 #9
0
/**
 * Retrieve inventory record with LineItems
 */
function vtws_retrieve_inventory($id)
{
    $current_user = vglobal('current_user');
    $record = vtws_retrieve($id, $current_user);
    $handler = vtws_getModuleHandlerFromName('LineItem', $user);
    $id = vtws_getIdComponents($id);
    $id = $id[1];
    $inventoryLineItems = $handler->getAllLineItemForParent($id);
    $record['LineItems'] = $inventoryLineItems;
    return $record;
}
コード例 #10
0
 public function delete($id)
 {
     $ids = vtws_getIdComponents($id);
     $elemId = $ids[1];
     $result = null;
     $query = 'update ' . $this->entityTableName . ' set deleted=1 where ' . $this->meta->getObectIndexColumn() . '=?';
     $transactionSuccessful = vtws_runQueryAsTransaction($query, array($elemId), $result);
     if (!$transactionSuccessful) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
     }
     return array("status" => "successful");
 }
コード例 #11
0
ファイル: getRecordImages.php プロジェクト: kduqi/corebos
function cbws_getrecordimageinfo($id, $user)
{
    global $log, $adb, $site_URL;
    $log->debug("Entering function cbws_getrecordimageinfo({$id})");
    $webserviceObject = VtigerWebserviceObject::fromId($adb, $id);
    $handlerPath = $webserviceObject->getHandlerPath();
    $handlerClass = $webserviceObject->getHandlerClass();
    require_once $handlerPath;
    $handler = new $handlerClass($webserviceObject, $user, $adb, $log);
    $meta = $handler->getMeta();
    $entityName = $meta->getObjectEntityName($id);
    $types = vtws_listtypes(null, $user);
    if (!in_array($entityName, $types['types'])) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to perform the operation is denied");
    }
    if ($meta->hasReadAccess() !== true) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to read entity is denied");
    }
    if ($entityName !== $webserviceObject->getEntityName()) {
        throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Id specified is incorrect");
    }
    if (!$meta->hasPermission(EntityMeta::$RETRIEVE, $id)) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to read given object is denied");
    }
    $idComponents = vtws_getIdComponents($id);
    if (!$meta->exists($idComponents[1])) {
        throw new WebServiceException(WebServiceErrorCode::$RECORDNOTFOUND, "Record you are trying to access is not found");
    }
    $ids = vtws_getIdComponents($id);
    $pdoid = $ids[1];
    $rdo = array();
    $query = 'select vtiger_attachments.name, vtiger_attachments.type, vtiger_attachments.attachmentsid, vtiger_attachments.path
			from vtiger_attachments
			inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_attachments.attachmentsid
			inner join vtiger_seattachmentsrel on vtiger_attachments.attachmentsid=vtiger_seattachmentsrel.attachmentsid
			where (vtiger_crmentity.setype LIKE "%Image" or vtiger_crmentity.setype LIKE "%Attachment")
			  and deleted=0 and vtiger_seattachmentsrel.crmid=?';
    $result_image = $adb->pquery($query, array($pdoid));
    $rdo['results'] = $adb->num_rows($result_image);
    $rdo['images'] = array();
    while ($img = $adb->fetch_array($result_image)) {
        $imga = array();
        $imga['name'] = $img['name'];
        $imga['path'] = $img['path'];
        $imga['fullpath'] = $site_URL . '/' . $img['path'] . $img['attachmentsid'] . '_' . $img['name'];
        $imga['type'] = $img['type'];
        $imga['id'] = $img['attachmentsid'];
        $rdo['images'][] = $imga;
    }
    VTWS_PreserveGlobal::flush();
    $log->debug("Leaving function cbws_getrecordimageinfo");
    return $rdo;
}
コード例 #12
0
 function process(Mobile_API_Request $request)
 {
     global $current_user, $adb, $currentModule;
     $current_user = $this->getActiveUser();
     $response = new Mobile_API_Response();
     $record = $request->get('record');
     $relatedmodule = $request->get('relatedmodule');
     $currentPage = $request->get('page', 0);
     // Input validation
     if (empty($record)) {
         $response->setError(1001, 'Record id is empty');
         return $response;
     }
     $recordid = vtws_getIdComponents($record);
     $recordid = $recordid[1];
     $module = Mobile_WS_Utils::detectModulenameFromRecordId($record);
     // Initialize global variable
     $currentModule = $module;
     $functionHandler = Mobile_WS_Utils::getRelatedFunctionHandler($module, $relatedmodule);
     if ($functionHandler) {
         $sourceFocus = CRMEntity::getInstance($module);
         $relationResult = call_user_func_array(array($sourceFocus, $functionHandler), array($recordid, getTabid($module), getTabid($relatedmodule)));
         $query = $relationResult['query'];
         $querySEtype = "vtiger_crmentity.setype as setype";
         if ($relatedmodule == 'Calendar') {
             $querySEtype = "vtiger_activity.activitytype as setype";
         }
         $query = sprintf("SELECT vtiger_crmentity.crmid, {$querySEtype} %s", substr($query, stripos($query, 'FROM')));
         $queryResult = $adb->query($query);
         // Gather resolved record id's
         $relatedRecords = array();
         while ($row = $adb->fetch_array($queryResult)) {
             $targetSEtype = $row['setype'];
             if ($relatedmodule == 'Calendar') {
                 if ($row['setype'] != 'Task' && $row['setype'] != 'Emails') {
                     $targetSEtype = 'Events';
                 } else {
                     $targetSEtype = $relatedmodule;
                 }
             }
             $relatedRecords[] = sprintf("%sx%s", Mobile_WS_Utils::getEntityModuleWSId($targetSEtype), $row['crmid']);
         }
         // Perform query to get record information with grouping
         $wsquery = sprintf("SELECT * FROM %s WHERE id IN ('%s');", $relatedmodule, implode("','", $relatedRecords));
         $newRequest = new Mobile_API_Request();
         $newRequest->set('module', $relatedmodule);
         $newRequest->set('query', $wsquery);
         $newRequest->set('page', $currentPage);
         $response = parent::process($newRequest);
     }
     return $response;
 }
コード例 #13
0
function vtws_internal_setrelation($elementId, $moduleName, $withTheseIds)
{
    global $adb;
    if (!is_array($withTheseIds)) {
        $withTheseIds = array($withTheseIds);
    }
    $focus = CRMEntity::getInstance($moduleName);
    foreach ($withTheseIds as $withThisId) {
        list($withModuleId, $withElementId) = vtws_getIdComponents($withThisId);
        $withModuleName = $adb->query_result($adb->pquery('select name from vtiger_ws_entity where id=?', array($withModuleId)), 0, 0);
        relateEntities($focus, $moduleName, $elementId, $withModuleName, $withElementId);
    }
}
コード例 #14
0
ファイル: AddRecordComment.php プロジェクト: kduqi/corebos
 function saveCommentToHelpDesk($commentcontent, $record, $user)
 {
     global $current_user;
     $current_user = $user;
     $targetModule = 'HelpDesk';
     $recordComponents = vtws_getIdComponents($record);
     $focus = CRMEntity::getInstance('HelpDesk');
     $focus->retrieve_entity_info($recordComponents[1], $targetModule);
     $focus->id = $recordComponents[1];
     $focus->mode = 'edit';
     $focus->column_fields['comments'] = $commentcontent;
     $focus->save($targetModule);
     return false;
 }
コード例 #15
0
/**
 * Save the attachment to the database
 */
function SaveAttachmentDB($element)
{
    global $adb;
    $attachid = $adb->getUniqueId('vtiger_crmentity');
    $filename = $element['name'];
    $description = $filename;
    $date_var = $adb->formatDate(date('YmdHis'), true);
    $usetime = $adb->formatDate($date_var, true);
    $userid = vtws_getIdComponents($element['assigned_user_id']);
    $userid = $userid[1];
    $setype = $element['setype'];
    $adb->pquery("INSERT INTO vtiger_crmentity(crmid, smcreatorid, smownerid,\n\t\t\t\tmodifiedby, setype, description, createdtime, modifiedtime, presence, deleted)\n\t\t\t\tVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array($attachid, $userid, $userid, $userid, $setype, $description, $usetime, $usetime, 1, 0));
    SaveAttachmentFile($attachid, $filename, $element['content']);
    return $attachid;
}
コード例 #16
0
 function sanitizeForInsert($row, $meta)
 {
     global $adb;
     $associatedToUser = false;
     if (strtolower($meta->getEntityName()) == "emails") {
         if (isset($row['parent_id'])) {
             $components = vtws_getIdComponents($row['parent_id']);
             if ($components[0] == VtigerWebserviceObject::fromName($adb, 'Users')) {
                 $associatedToUser = true;
             }
         }
     }
     $references = $meta->getReferenceFieldDetails();
     foreach ($references as $field => $typeList) {
         if (strpos($row[$field], 'x') !== false) {
             $row[$field] = vtws_getIdComponents($row[$field]);
             $row[$field] = $row[$field][1];
         }
     }
     $ownerFields = $meta->getOwnerFields();
     foreach ($ownerFields as $index => $field) {
         if (isset($row[$field]) && $row[$field] != null) {
             $ownerDetails = vtws_getIdComponents($row[$field]);
             $row[$field] = $ownerDetails[1];
         }
     }
     if (strtolower($meta->getEntityName()) == "emails") {
         if (isset($row['parent_id'])) {
             if ($associatedToUser === true) {
                 $_REQUEST['module'] = 'Emails';
                 $row['parent_id'] = $row['parent_id'] . "@-1|";
                 $_REQUEST['parent_id'] = $row['parent_id'];
             } else {
                 $emailFields = $meta->getEmailFields();
                 $fieldId = getEmailFieldId($meta, $row['parent_id'], $emailFields);
                 $row['parent_id'] = $row['parent_id'] . "@{$fieldId}|";
             }
         }
     }
     if ($row["id"]) {
         unset($row["id"]);
     }
     if (isset($row[$meta->getObectIndexColumn()])) {
         unset($row[$meta->getObectIndexColumn()]);
     }
     return $row;
 }
コード例 #17
0
ファイル: Contacts.php プロジェクト: rcrrich/UpdatePackages
 protected function pullContactsBySupportEndDate($feed, $start, $end, &$result, $color = null, $textColor = 'white')
 {
     $query = "SELECT firstname,lastname,support_end_date FROM Contacts";
     $query .= " WHERE support_end_date >= '{$start}' AND support_end_date <= '{$end}'";
     $records = $feed->queryForRecords($query);
     foreach ($records as $record) {
         $item = array();
         list($modid, $crmid) = vtws_getIdComponents($record['id']);
         $item['id'] = $crmid;
         $item['title'] = decode_html(trim($record['firstname'] . ' ' . $record['lastname']));
         $item['start'] = $record['support_end_date'];
         $item['url'] = sprintf('index.php?module=Contacts&view=Detail&record=%s', $crmid);
         $item['color'] = $color;
         $item['textColor'] = $textColor;
         $result[] = $item;
     }
 }
コード例 #18
0
ファイル: Invoice.php プロジェクト: rcrrich/UpdatePackages
 public function process($feed, $request, $start, $end, &$result, $userid = false, $color = null, $textColor = 'white')
 {
     $query = "SELECT subject,duedate FROM Invoice";
     $query .= " WHERE duedate >= '{$start}' AND duedate <= '{$end}'";
     $records = $feed->queryForRecords($query);
     foreach ($records as $record) {
         $item = array();
         list($modid, $crmid) = vtws_getIdComponents($record['id']);
         $item['id'] = $crmid;
         $item['title'] = decode_html($record['subject']);
         $item['start'] = $record['duedate'];
         $item['url'] = sprintf('index.php?module=Invoice&view=Detail&record=%s', $crmid);
         $item['color'] = $color;
         $item['textColor'] = $textColor;
         $result[] = $item;
     }
 }
コード例 #19
0
 public function create($elementType, $element)
 {
     $db = PearDatabase::getInstance();
     $sql = 'SELECT * FROM vtiger_producttaxrel WHERE productid =? AND taxid=?';
     list($typeId, $productId) = vtws_getIdComponents($element['productid']);
     list($typeId, $taxId) = vtws_getIdComponents($element['taxid']);
     $params = array($productId, $taxId);
     $result = $db->pquery($sql, $params);
     $rowCount = $db->num_rows($result);
     if ($rowCount > 0) {
         $id = $db->query_result($result, 0, $this->meta->getObectIndexColumn());
         $meta = $this->getMeta();
         $element['id'] = vtws_getId($meta->getEntityId(), $id);
         return $this->update($element);
     } else {
         unset($element['id']);
         return parent::create($elementType, $element);
     }
 }
コード例 #20
0
/**
 * @author MAK
 */
function vtws_deleteUser($id, $newOwnerId, $user)
{
    global $log, $adb;
    $webserviceObject = VtigerWebserviceObject::fromId($adb, $id);
    $handlerPath = $webserviceObject->getHandlerPath();
    $handlerClass = $webserviceObject->getHandlerClass();
    require_once $handlerPath;
    $handler = new $handlerClass($webserviceObject, $user, $adb, $log);
    $meta = $handler->getMeta();
    $entityName = $meta->getObjectEntityName($id);
    $types = vtws_listtypes($user);
    if (!in_array($entityName, $types['types'])) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to perform the operation is denied, EntityName = " . $entityName);
    }
    if ($entityName !== $webserviceObject->getEntityName()) {
        throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Id specified is incorrect");
    }
    if (!$meta->hasPermission(EntityMeta::$DELETE, $id)) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to read given object is denied");
    }
    $idComponents = vtws_getIdComponents($id);
    if (!$meta->exists($idComponents[1])) {
        throw new WebServiceException(WebServiceErrorCode::$RECORDNOTFOUND, "Record you are trying to access is not found, idComponent = " . $idComponents);
    }
    if ($meta->hasWriteAccess() !== true) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to write is denied");
    }
    $newIdComponents = vtws_getIdComponents($newOwnerId);
    if (empty($newIdComponents[1])) {
        //force the default user to be the default admin user.
        //added cause eazybusiness team is sending this value empty
        $newIdComponents[1] = 1;
    }
    vtws_transferOwnership($idComponents[1], $newIdComponents[1]);
    //delete from user vtiger_table;
    $sql = "delete from vtiger_users where id=?";
    vtws_runQueryAsTransaction($sql, array($idComponents[1]), $result);
    VTWS_PreserveGlobal::flush();
    return array("status" => "successful");
}
コード例 #21
0
 function process(Mobile_API_Request $request)
 {
     global $current_user, $adb, $currentModule;
     $current_user = $this->getActiveUser();
     $response = new Mobile_API_Response();
     $record = $request->get('record');
     $currentPage = $request->get('page', 0);
     // Input validation
     if (empty($record)) {
         $response->setError(1001, 'Record id is empty');
         return $response;
     }
     $recordid = vtws_getIdComponents($record);
     $recordid = $recordid[1];
     $module = Mobile_WS_Utils::detectModulenameFromRecordId($record);
     // Initialize global variable
     $currentModule = $module;
     //related module currently supported
     $relatedmodule = array('Contacts', 'Potentials', 'HelpDesk');
     $activemodule = $this->sessionGet('_MODULES');
     foreach ($activemodule as $amodule) {
         if (in_array($amodule->name(), $relatedmodule)) {
             $active_related_module[] = $amodule->name();
         }
     }
     foreach ($active_related_module as $relmod) {
         $functionHandler = Mobile_WS_Utils::getRelatedFunctionHandler($module, $relmod);
         $fieldmodel = new Mobile_UI_FieldModel();
         if ($functionHandler) {
             $sourceFocus = CRMEntity::getInstance($module);
             $relationResult = call_user_func_array(array($sourceFocus, $functionHandler), array($recordid, getTabid($module), getTabid($relmod)));
             $relatedRecords[$relmod] = array_keys($relationResult['entries']);
             $response->setResult($relatedRecords);
         } else {
             $response->setError(1018, 'Function Handler for module ' . $module . ' for related Module ' . $relmod . '  not found.');
         }
     }
     return $response;
 }
コード例 #22
0
ファイル: addComment.php プロジェクト: kduqi/corebos
 function getContent(Mobile_API_Request $request)
 {
     $comment = $request->get('comment');
     $parentid = $request->get('parentid');
     if (isset($comment) && !empty($comment)) {
         $parentmodule = Mobile_WS_Utils::detectModulenameFromRecordId($parentid);
         if ($parentmodule != 'HelpDesk') {
             include_once 'include/Webservices/Create.php';
             $current_user = $this->getActiveUser();
             $userid = Mobile_WS_Utils::getEntityModuleWSId('Users') . "x" . $current_user->id;
             $arr_comment = array('commentcontent' => $comment, 'related_to' => $parentid, 'creator' => $userid, 'assigned_user_id' => $userid);
             $ele = vtws_create('ModComments', $arr_comment, $current_user);
         } else {
             $parentrecordid = vtws_getIdComponents($parentid);
             $parentrecordid = $parentrecordid[1];
             //there is currently no vtws service available for ticket comments
             $current_user = $this->getActiveUser();
             $current_user_id = $current_user->id;
             $userrecordid = vtws_getIdComponents($current_user_id);
             $userrecordid = $userrecordid[1];
             $arr_comment = array('commentcontent' => $comment, 'related_to' => $parentrecordid, 'creator' => $current_user_id);
             //$ele = vtws_create('ModComments', $arr_comment, $current_user);
             $saverecord = Mobile_WS_Utils::createTicketComment($arr_comment);
             if ($saverecord == true) {
                 $userid = Mobile_WS_Utils::getEntityModuleWSId('Users') . "x" . $current_user_id;
                 $ele['commentcontent'] = $arr_comment['commentcontent'];
                 $ele['creator'] = $userid;
                 $ele['assigned_user_id'] = $userid;
                 $ele['related_to'] = $parentid;
                 $ele['id'] = '';
                 $ele['createdtime'] = DateTimeField::convertToUserFormat(date('Y-m-d H:i:s'));
             }
         }
     }
     $response = new Mobile_API_Response();
     $ele['assigned_user_id'] = vtws_getName($ele['creator'], $current_user);
     $response->setResult(array('comment' => $ele));
     return $response;
 }
コード例 #23
0
function cbws_getpdfdata($id, $user)
{
    global $log, $adb;
    $log->debug("Entering function vtws_getpdfdata");
    $webserviceObject = VtigerWebserviceObject::fromId($adb, $id);
    $handlerPath = $webserviceObject->getHandlerPath();
    $handlerClass = $webserviceObject->getHandlerClass();
    require_once $handlerPath;
    $handler = new $handlerClass($webserviceObject, $user, $adb, $log);
    $meta = $handler->getMeta();
    $entityName = $meta->getObjectEntityName($id);
    $types = vtws_listtypes(null, $user);
    if (!in_array($entityName, $types['types'])) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to perform the operation is denied");
    }
    if ($meta->hasReadAccess() !== true) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to write is denied");
    }
    if ($entityName !== $webserviceObject->getEntityName()) {
        throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Id specified is incorrect");
    }
    if (!$meta->hasPermission(EntityMeta::$RETRIEVE, $id)) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to read given object is denied");
    }
    $idComponents = vtws_getIdComponents($id);
    if (!$meta->exists($idComponents[1])) {
        throw new WebServiceException(WebServiceErrorCode::$RECORDNOTFOUND, "Record you are trying to access is not found");
    }
    $objectName = $webserviceObject->getEntityName();
    if (!in_array($objectName, array('Invoice', 'Quotes', 'SalesOrder', 'PurchaseOrder'))) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Only Inventory modules support PDF Output.");
    }
    $ids = vtws_getIdComponents($id);
    $document_id = $ids[1];
    $entity = get_module_pdf($objectName, $document_id);
    VTWS_PreserveGlobal::flush();
    $log->debug("Leaving function vtws_getpdfdata");
    return $entity;
}
コード例 #24
0
ファイル: DeleteUser.php プロジェクト: Bergdahls/YetiForceCRM
/**
 * @author MAK
 */
function vtws_deleteUser($id, $newOwnerId, $user)
{
    $adb = PearDatabase::getInstance();
    $log = vglobal('log');
    $webserviceObject = VtigerWebserviceObject::fromId($adb, $id);
    $handlerPath = $webserviceObject->getHandlerPath();
    $handlerClass = $webserviceObject->getHandlerClass();
    require_once $handlerPath;
    $handler = new $handlerClass($webserviceObject, $user, $adb, $log);
    $meta = $handler->getMeta();
    $entityName = $meta->getObjectEntityName($id);
    $types = vtws_listtypes(null, $user);
    if (!in_array($entityName, $types['types'])) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to perform the operation is denied, EntityName = " . $entityName);
    }
    if ($entityName !== $webserviceObject->getEntityName()) {
        throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Id specified is incorrect");
    }
    if (!$meta->hasPermission(EntityMeta::$DELETE, $id)) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to read given object is denied");
    }
    $idComponents = vtws_getIdComponents($id);
    if (!$meta->exists($idComponents[1])) {
        throw new WebServiceException(WebServiceErrorCode::$RECORDNOTFOUND, "Record you are trying to access is not found, idComponent = " . $idComponents);
    }
    if ($meta->hasWriteAccess() !== true) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to write is denied");
    }
    $newIdComponents = vtws_getIdComponents($newOwnerId);
    if (empty($newIdComponents[1])) {
        //force the default user to be the default admin user.
        $newIdComponents[1] = 1;
    }
    $userObj = new Users();
    $userObj->transformOwnerShipAndDelete($idComponents[1], $newIdComponents[1]);
    VTWS_PreserveGlobal::flush();
    return array("status" => "successful");
}
コード例 #25
0
 public function updateParent($createdElement, $parent)
 {
     $discount = 0;
     $parentId = vtws_getIdComponents($parent['id']);
     $parentId = $parentId[1];
     $lineItemList = $this->getAllLineItemForParent($parentId);
     $parent['hdnSubTotal'] = 0;
     $taxAmount = 0;
     foreach ($lineItemList as $lineItem) {
         $discount = 0;
         $lineItemTotal = $lineItem['listprice'] * $lineItem['quantity'];
         $lineItem['discount_amount'] = (double) $lineItem['discount_amount'];
         $lineItem['discount_percent'] = (double) $lineItem['discount_percent'];
         if (!empty($lineItem['discount_amount'])) {
             $discount = $lineItem['discount_amount'];
         } elseif (!empty($lineItem['discount_percent'])) {
             $discount = $lineItem['discount_percent'] / 100 * $lineItemTotal;
         }
         $this->initTax($lineItem, $parent);
         $lineItemTotal = $lineItemTotal - $discount;
         $parent['hdnSubTotal'] = $parent['hdnSubTotal'] + $lineItemTotal;
         if (strcasecmp($parent['hdnTaxType'], $this->Individual) === 0) {
             foreach ($this->taxList as $taxInfo) {
                 $lineItemTaxAmount = $taxInfo['percentage'] / 100 * $lineItemTotal;
                 $parent['hdnSubTotal'] += $lineItemTaxAmount;
             }
         }
     }
     if (!empty($parent['hdnDiscountAmount']) && (double) $parent['hdnDiscountAmount'] > 0) {
         $discount = $parent['hdnDiscountAmount'];
     } elseif (!empty($parent['hdnDiscountPercent'])) {
         $discount = $parent['hdnDiscountPercent'] / 100 * $parent['hdnSubTotal'];
     }
     $parent['pre_tax_total'] = $total = $parent['hdnSubTotal'] - $discount + $parent['hdnS_H_Amount'];
     $taxTotal = $parent['hdnSubTotal'] - $discount;
     if (strcasecmp($parent['hdnTaxType'], $this->Individual) !== 0) {
         $this->initTax($createdElement, $parent);
         foreach ($this->taxList as $taxInfo) {
             $taxAmount += $taxInfo['percentage'] / 100 * $taxTotal;
         }
     }
     $shippingTax = getAllTaxes('all', 'sh', 'edit', $parentId);
     $shippingTaxInfo = array();
     foreach ($shippingTax as $taxInfo) {
         $taxAmount += $taxInfo['percentage'] / 100 * $parent['hdnS_H_Amount'];
         $shippingTaxInfo[$taxInfo['taxname']] = $taxInfo['percentage'];
     }
     $parent['hdnGrandTotal'] = $total + $taxAmount + $parent['txtAdjustment'];
     $parentTypeHandler = vtws_getModuleHandlerFromId($parent['id'], $this->user);
     $parentTypeMeta = $parentTypeHandler->getMeta();
     $parentType = $parentTypeMeta->getEntityName();
     $parentInstance = CRMEntity::getInstance($parentType);
     $sql = 'update ' . $parentInstance->table_name . ' set subtotal=?, total=?, pre_tax_total=? where ' . $parentInstance->tab_name_index[$parentInstance->table_name] . '=?';
     $params = array($parent['hdnSubTotal'], $parent['hdnGrandTotal'], $parent['pre_tax_total'], $parentId);
     $transactionSuccessful = vtws_runQueryAsTransaction($sql, $params, $result);
     self::$parentCache[$parent['id']] = $parent;
     if (!$transactionSuccessful) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
     }
 }
コード例 #26
0
function vtws_addTicketFaqComment($id, $values, $user)
{
    global $log, $adb, $current_user;
    $webserviceObject = VtigerWebserviceObject::fromId($adb, $id);
    $handlerPath = $webserviceObject->getHandlerPath();
    $handlerClass = $webserviceObject->getHandlerClass();
    require_once $handlerPath;
    $handler = new $handlerClass($webserviceObject, $user, $adb, $log);
    $meta = $handler->getMeta();
    $entityName = $meta->getObjectEntityName($id);
    if ($entityName !== 'HelpDesk' and $entityName !== 'Faq') {
        throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Invalid module specified. Must be HelpDesk or Faq");
    }
    if ($meta->hasReadAccess() !== true) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to write is denied");
    }
    if ($entityName !== $webserviceObject->getEntityName()) {
        throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Id specified is incorrect");
    }
    if (!$meta->hasPermission(EntityMeta::$RETRIEVE, $id)) {
        throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to read given object is denied");
    }
    $idComponents = vtws_getIdComponents($id);
    if (!$meta->exists($idComponents[1])) {
        throw new WebServiceException(WebServiceErrorCode::$RECORDNOTFOUND, "Record you are trying to access is not found");
    }
    $comment = trim($values['comments']);
    if (empty($comment)) {
        throw new WebServiceException(WebServiceErrorCode::$MANDFIELDSMISSING, "Comment empty.");
    }
    $current_time = $adb->formatDate(date('Y-m-d H:i:s'), true);
    if ($entityName == 'HelpDesk') {
        if ($values['from_portal'] != 1) {
            $ownertype = 'user';
            if (!empty($user)) {
                $ownerId = $user->id;
            } elseif (!empty($current_user)) {
                $ownerId = $current_user->id;
            } else {
                $ownerId = 1;
            }
            //get the user email
            $result = $adb->pquery("SELECT email1 FROM vtiger_users WHERE id=?", array($ownerId));
            $fromname = getUserFullName($ownerId);
        } else {
            $ownertype = 'customer';
            $webserviceObject = VtigerWebserviceObject::fromId($adb, $values['parent_id']);
            $handlerPath = $webserviceObject->getHandlerPath();
            $handlerClass = $webserviceObject->getHandlerClass();
            require_once $handlerPath;
            $handler = new $handlerClass($webserviceObject, $user, $adb, $log);
            $meta = $handler->getMeta();
            $entityName = $meta->getObjectEntityName($values['parent_id']);
            if ($entityName !== 'Contacts') {
                throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Invalid owner module specified. Must be Contacts");
            }
            if ($entityName !== $webserviceObject->getEntityName()) {
                throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Id specified is incorrect");
            }
            $pidComponents = vtws_getIdComponents($values['parent_id']);
            if (!$meta->exists($pidComponents[1])) {
                throw new WebServiceException(WebServiceErrorCode::$RECORDNOTFOUND, "Record you are trying to access is not found");
            }
            $ownerId = $pidComponents[1];
            //get the contact email id who creates the ticket from portal and use this email as from email id in email
            $result = $adb->pquery("SELECT email FROM vtiger_contactdetails WHERE contactid=?", array($ownerId));
            $ename = getEntityName('Contacts', $ownerId);
            $fromname = $ename[$ownerId];
        }
        $sql = "insert into vtiger_ticketcomments values(?,?,?,?,?,?)";
        $params = array('', $idComponents[1], $comment, $ownerId, $ownertype, $current_time);
        //send mail to the assigned to user when customer add comment
        $toresult = $adb->pquery("SELECT email1,first_name\n\t\t\t\t\tFROM vtiger_users\n\t\t\t\t\tINNER JOIN vtiger_crmentity on smownerid=id\n\t\t\t\t\tINNER JOIN vtiger_troubletickets on ticketid=crmid\n\t\t\t\t\tWHERE ticketid=?", array($idComponents[1]));
        $to_email = $adb->query_result($toresult, 0, 0);
        $ownerName = $adb->query_result($toresult, 0, 1);
        $moduleName = 'HelpDesk';
        $subject = getTranslatedString('LBL_RESPONDTO_TICKETID', $moduleName) . "##" . $idComponents[1] . "##" . getTranslatedString('LBL_CUSTOMER_PORTAL', $moduleName);
        $contents = getTranslatedString('Dear', $moduleName) . " " . $ownerName . "," . "<br><br>" . getTranslatedString('LBL_CUSTOMER_COMMENTS', $moduleName) . "<br><br>\n\t\t\t\t\t<b>" . $comment . "</b><br><br>" . getTranslatedString('LBL_RESPOND', $moduleName) . "<br><br>" . getTranslatedString('LBL_REGARDS', $moduleName) . "<br>" . getTranslatedString('LBL_SUPPORT_ADMIN', $moduleName);
        $from_email = $adb->query_result($result, 0, 0);
        //send mail to assigned to user
        $mail_status = send_mail('HelpDesk', $to_email, $fromname, $from_email, $subject, $contents);
    } else {
        $sql = "insert into vtiger_faqcomments values(?, ?, ?, ?)";
        $params = array('', $idComponents[1], $comment, $current_time);
    }
    $adb->pquery($sql, $params);
    VTWS_PreserveGlobal::flush();
    return array('success' => true);
}
コード例 #27
0
ファイル: InventoryUtils.php プロジェクト: jaimeaga84/corebos
function updateInventoryProductRel($entity)
{
    global $log, $adb, $updateInventoryProductRel_update_product_array;
    $entity_id = vtws_getIdComponents($entity->getId());
    $entity_id = $entity_id[1];
    $update_product_array = $updateInventoryProductRel_update_product_array;
    $log->debug("Entering into function updateInventoryProductRel(" . $entity_id . ").");
    if (!empty($update_product_array)) {
        foreach ($update_product_array as $id => $seq) {
            foreach ($seq as $seq => $product_info) {
                foreach ($product_info as $key => $index) {
                    $updqtyinstk = getPrdQtyInStck($key);
                    $upd_qty = $updqtyinstk + $index;
                    updateProductQty($key, $upd_qty);
                }
            }
        }
    }
    $adb->pquery("UPDATE vtiger_inventoryproductrel SET incrementondel=1 WHERE id=?", array($entity_id));
    $product_info = $adb->pquery("SELECT productid,sequence_no, quantity from vtiger_inventoryproductrel WHERE id=?", array($entity_id));
    $numrows = $adb->num_rows($product_info);
    for ($index = 0; $index < $numrows; $index++) {
        $productid = $adb->query_result($product_info, $index, 'productid');
        $qty = $adb->query_result($product_info, $index, 'quantity');
        $sequence_no = $adb->query_result($product_info, $index, 'sequence_no');
        $qtyinstk = getPrdQtyInStck($productid);
        $upd_qty = $qtyinstk - $qty;
        updateProductQty($productid, $upd_qty);
        $sub_prod_query = $adb->pquery("SELECT productid from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($entity_id, $sequence_no));
        if ($adb->num_rows($sub_prod_query) > 0) {
            for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                $sub_prod_id = $adb->query_result($sub_prod_query, $j, "productid");
                $sqtyinstk = getPrdQtyInStck($sub_prod_id);
                $supd_qty = $sqtyinstk - $qty;
                updateProductQty($sub_prod_id, $supd_qty);
            }
        }
    }
    $log->debug("Exit from function updateInventoryProductRel(" . $entity_id . ")");
}
コード例 #28
0
 public function getName($webserviceId)
 {
     $idComponents = vtws_getIdComponents($webserviceId);
     $entityId = $idComponents[0];
     $id = $idComponents[1];
     $nameList = vtws_getActorEntityNameById($entityId, array($id));
     return $nameList[$id];
 }
コード例 #29
0
ファイル: Mail.php プロジェクト: nouphet/vtigercrm-6.0.0-ja
 /**
  * Function which processes request for Mail Operations
  * @global Integer $list_max_entries_per_page - Number of entries per page
  * @global PearDataBase Instance $adb
  * @global Users Instance $current_user
  * @global String $root_directory
  * @param Vtiger_Request $request
  * @return MailManager_Response
  */
 function process(Vtiger_Request $request)
 {
     global $list_max_entries_per_page, $adb, $current_user;
     $moduleName = $request->getModule();
     $response = new Vtiger_Response();
     if ('open' == $this->getOperationArg($request)) {
         $foldername = $request->get('_folder');
         $connector = $this->getConnector($foldername);
         $folder = $connector->folderInstance($foldername);
         $connector->markMailRead($request->get('_msgno'));
         $mail = $connector->openMail($request->get('_msgno'));
         // Get updated count after opening the email
         $connector->updateFolder($folder, SA_MESSAGES | SA_UNSEEN);
         $viewer = $this->getViewer($request);
         $viewer->assign('FOLDER', $folder);
         $viewer->assign('MAIL', $mail);
         $viewer->assign('MODULE', $moduleName);
         $uicontent = $viewer->view('MailOpen.tpl', 'MailManager', true);
         $metainfo = array('from' => $mail->from(), 'subject' => $mail->subject(), 'msgno' => $mail->msgNo(), 'msguid' => $mail->uniqueid(), 'folder' => $foldername);
         $response->isJson(true);
         $response->setResult(array('folder' => $foldername, 'unread' => $folder->unreadCount(), 'ui' => $uicontent, 'meta' => $metainfo));
     } else {
         if ('mark' == $this->getOperationArg($request)) {
             $foldername = $request->get('_folder');
             $connector = $this->getConnector($foldername);
             $folder = $connector->folderInstance($foldername);
             $connector->updateFolder($folder, SA_UNSEEN);
             if ('unread' == $request->get('_markas')) {
                 $connector->markMailUnread($request->get('_msgno'));
             }
             $response->isJson(true);
             $response->setResult(array('folder' => $foldername, 'unread' => $folder->unreadCount() + 1, 'status' => true, 'msgno' => $request->get('_msgno')));
         } else {
             if ('delete' == $this->getOperationArg($request)) {
                 $msg_no = $request->get('_msgno');
                 $foldername = $request->get('_folder');
                 $connector = $this->getConnector($foldername);
                 $connector->deleteMail($msg_no);
                 $response->isJson(true);
                 $response->setResult(array('folder' => $foldername, 'status' => true));
             } else {
                 if ('move' == $this->getOperationArg($request)) {
                     $msg_no = $request->get('_msgno');
                     $foldername = $request->get('_folder');
                     $moveToFolder = $request->get('_moveFolder');
                     $connector = $this->getConnector($foldername);
                     $connector->moveMail($msg_no, $moveToFolder);
                     $response->isJson(true);
                     $response->setResult(array('folder' => $foldername, 'status' => true));
                 } else {
                     if ('send' == $this->getOperationArg($request)) {
                         require_once 'modules/MailManager/Config.php';
                         // This is to handle larger uploads
                         $memory_limit = MailManager_Config::get('MEMORY_LIMIT');
                         ini_set('memory_limit', $memory_limit);
                         $to_string = rtrim($request->get('to'), ',');
                         $connector = $this->getConnector('__vt_drafts');
                         if (!empty($to_string)) {
                             $toArray = explode(',', $to_string);
                             foreach ($toArray as $to) {
                                 $relatedtos = MailManager::lookupMailInVtiger($to, $current_user);
                                 $referenceArray = array('Contacts', 'Accounts', 'Leads');
                                 for ($j = 0; $j < count($referenceArray); $j++) {
                                     $val = $referenceArray[$j];
                                     if (!empty($relatedtos) && is_array($relatedtos)) {
                                         for ($i = 0; $i < count($relatedtos); $i++) {
                                             if ($i == count($relatedtos) - 1) {
                                                 $relateto = vtws_getIdComponents($relatedtos[$i]['record']);
                                                 $parentIds = $relateto[1] . "@1";
                                             } elseif ($relatedtos[$i]['module'] == $val) {
                                                 $relateto = vtws_getIdComponents($relatedtos[$i]['record']);
                                                 $parentIds = $relateto[1] . "@1";
                                                 break;
                                             }
                                         }
                                     }
                                     if (isset($parentIds)) {
                                         break;
                                     }
                                 }
                                 if ($parentIds == '') {
                                     if (count($relatedtos) > 0) {
                                         $relateto = vtws_getIdComponents($relatedtos[0]['record']);
                                         $parentIds = $relateto[1] . "@1";
                                         break;
                                     }
                                 }
                                 $cc_string = rtrim($request->get('cc'), ',');
                                 $bcc_string = rtrim($request->get('bcc'), ',');
                                 $subject = $request->get('subject');
                                 $body = $request->get('body');
                                 //Restrict this for users module
                                 if ($relateto[1] != NULL && $relateto[0] != '19') {
                                     $entityId = $relateto[1];
                                     $parent_module = getSalesEntityType($entityId);
                                     $description = getMergedDescription($body, $entityId, $parent_module);
                                 } else {
                                     if ($relateto[0] == '19') {
                                         $parentIds = $relateto[1] . '@-1';
                                     }
                                     $description = $body;
                                 }
                                 $fromEmail = $connector->getFromEmailAddress();
                                 $userFullName = getFullNameFromArray('Users', $current_user->column_fields);
                                 $userId = $current_user->id;
                                 $mailer = new Vtiger_Mailer();
                                 $mailer->IsHTML(true);
                                 $mailer->ConfigSenderInfo($fromEmail, $userFullName, $current_user->email1);
                                 $mailer->Subject = $subject;
                                 $mailer->Body = $description;
                                 $mailer->addSignature($userId);
                                 if ($mailer->Signature != '') {
                                     $mailer->Body .= $mailer->Signature;
                                 }
                                 $ccs = empty($cc_string) ? array() : explode(',', $cc_string);
                                 $bccs = empty($bcc_string) ? array() : explode(',', $bcc_string);
                                 $emailId = $request->get('emailid');
                                 $attachments = $connector->getAttachmentDetails($emailId);
                                 $mailer->AddAddress($to);
                                 foreach ($ccs as $cc) {
                                     $mailer->AddCC($cc);
                                 }
                                 foreach ($bccs as $bcc) {
                                     $mailer->AddBCC($bcc);
                                 }
                                 global $root_directory;
                                 if (is_array($attachments)) {
                                     foreach ($attachments as $attachment) {
                                         $fileNameWithPath = $root_directory . $attachment['path'] . $attachment['fileid'] . "_" . $attachment['attachment'];
                                         if (is_file($fileNameWithPath)) {
                                             $mailer->AddAttachment($fileNameWithPath, $attachment['attachment']);
                                         }
                                     }
                                 }
                                 $status = $mailer->Send(true);
                                 if ($status === true) {
                                     $email = CRMEntity::getInstance('Emails');
                                     $email->column_fields['assigned_user_id'] = $current_user->id;
                                     $email->column_fields['date_start'] = date('Y-m-d');
                                     $email->column_fields['time_start'] = date('H:i');
                                     $email->column_fields['parent_id'] = $parentIds;
                                     $email->column_fields['subject'] = $mailer->Subject;
                                     $email->column_fields['description'] = $mailer->Body;
                                     $email->column_fields['activitytype'] = 'Emails';
                                     $email->column_fields['from_email'] = $mailer->From;
                                     $email->column_fields['saved_toid'] = $to;
                                     $email->column_fields['ccmail'] = $cc_string;
                                     $email->column_fields['bccmail'] = $bcc_string;
                                     $email->column_fields['email_flag'] = 'SENT';
                                     if (empty($emailId)) {
                                         $email->save('Emails');
                                     } else {
                                         $email->id = $emailId;
                                         $email->mode = 'edit';
                                         $email->save('Emails');
                                     }
                                     // This is added since the Emails save_module is not handling this
                                     global $adb;
                                     $realid = explode("@", $parentIds);
                                     $mycrmid = $realid[0];
                                     $params = array($mycrmid, $email->id);
                                     if ($realid[1] == -1) {
                                         $adb->pquery('DELETE FROM vtiger_salesmanactivityrel WHERE smid=? AND activityid=?', $params);
                                         $adb->pquery('INSERT INTO vtiger_salesmanactivityrel VALUES (?,?)', $params);
                                     } else {
                                         $adb->pquery('DELETE FROM vtiger_seactivityrel WHERE crmid=? AND activityid=?', $params);
                                         $adb->pquery('INSERT INTO vtiger_seactivityrel VALUES (?,?)', $params);
                                     }
                                 }
                             }
                         }
                         if ($status === true) {
                             $response->isJson(true);
                             $response->setResult(array('sent' => true));
                         } else {
                             $response->isJson(true);
                             $response->setError(112, 'please verify outgoing server.');
                         }
                     } else {
                         if ('attachment_dld' == $this->getOperationArg($request)) {
                             $attachmentName = $request->get('_atname');
                             $attachmentName = str_replace(' ', '_', $attachmentName);
                             if (MailManager_Utils::allowedFileExtension($attachmentName)) {
                                 // This is to handle larger uploads
                                 $memory_limit = MailManager_Config::get('MEMORY_LIMIT');
                                 ini_set('memory_limit', $memory_limit);
                                 $mail = new MailManager_Message_Model(false, false);
                                 $mail->readFromDB($request->get('_muid'));
                                 $attachment = $mail->attachments(true, $attachmentName);
                                 if ($attachment[$attachmentName]) {
                                     // Send as downloadable
                                     header("Content-type: application/octet-stream");
                                     header("Pragma: public");
                                     header("Cache-Control: private");
                                     header("Content-Disposition: attachment; filename={$attachmentName}");
                                     echo $attachment[$attachmentName];
                                 } else {
                                     header("Content-Disposition: attachment; filename=INVALIDFILE");
                                     echo "";
                                 }
                             } else {
                                 header("Content-Disposition: attachment; filename=INVALIDFILE");
                                 echo "";
                             }
                             flush();
                             exit;
                         } elseif ('getdraftmail' == $this->getOperationArg($request)) {
                             $connector = $this->getConnector('__vt_drafts');
                             $draftMail = $connector->getDraftMail($request);
                             $response->isJson(true);
                             $response->setResult(array($draftMail));
                         } elseif ('save' == $this->getOperationArg($request)) {
                             $connector = $this->getConnector('__vt_drafts');
                             $draftId = $connector->saveDraft($request);
                             $response->isJson(true);
                             if (!empty($draftId)) {
                                 $response->setResult(array('success' => true, 'emailid' => $draftId));
                             } else {
                                 $response->setResult(array('success' => false, 'error' => "Draft was not saved"));
                             }
                         } elseif ('deleteAttachment' == $this->getOperationArg($request)) {
                             $connector = $this->getConnector('__vt_drafts');
                             $deleteResponse = $connector->deleteAttachment($request);
                             $response->isJson(true);
                             $response->setResult(array('success' => $deleteResponse));
                         } elseif ('forward' == $this->getOperationArg($request)) {
                             $messageId = $request->get('messageid');
                             $folderName = $request->get('folder');
                             $connector = $this->getConnector($folderName);
                             $mail = $connector->openMail($messageId);
                             $attachments = $mail->attachments(true);
                             $draftConnector = $this->getConnector('__vt_drafts');
                             $draftId = $draftConnector->saveDraft($request);
                             if (!empty($attachments)) {
                                 foreach ($attachments as $aName => $aValue) {
                                     $attachInfo = $mail->__SaveAttachmentFile($aName, $aValue);
                                     if (is_array($attachInfo) && !empty($attachInfo) && $attachInfo['size'] > 0) {
                                         if (!MailManager::checkModuleWriteAccessForCurrentUser('Documents')) {
                                             return;
                                         }
                                         $document = CRMEntity::getInstance('Documents');
                                         $document->column_fields['notes_title'] = $attachInfo['name'];
                                         $document->column_fields['filename'] = $attachInfo['name'];
                                         $document->column_fields['filestatus'] = 1;
                                         $document->column_fields['filelocationtype'] = 'I';
                                         $document->column_fields['folderid'] = 1;
                                         // Default Folder
                                         $document->column_fields['filesize'] = $attachInfo['size'];
                                         $document->column_fields['assigned_user_id'] = $current_user->id;
                                         $document->save('Documents');
                                         //save doc-attachment relation
                                         $draftConnector->saveAttachmentRel($document->id, $attachInfo['attachid']);
                                         //save email-doc relation
                                         $draftConnector->saveEmailDocumentRel($draftId, $document->id);
                                         //save email-attachment relation
                                         $draftConnector->saveAttachmentRel($draftId, $attachInfo['attachid']);
                                         $attachmentInfo[] = array('name' => $attachInfo['name'], 'size' => $attachInfo['size'], 'emailid' => $draftId, 'docid' => $document->id);
                                     }
                                     unset($aValue);
                                 }
                             }
                             $response->isJson(true);
                             $response->setResult(array('attachments' => $attachmentInfo, 'emailid' => $draftId));
                         }
                     }
                 }
             }
         }
     }
     return $response;
 }
コード例 #30
0
ファイル: VtigerActorOperation.php プロジェクト: hardikk/HNH
 public function delete($id)
 {
     $ids = vtws_getIdComponents($id);
     $elemId = $ids[1];
     $success = $this->__delete($elemId);
     if (!$success) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
     }
     return array("status" => "successful");
 }