本文整理汇总了PHP中Documents::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Documents::save方法的具体用法?PHP Documents::save怎么用?PHP Documents::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Documents
的用法示例。
在下文中一共展示了Documents::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadDocuments
/**
* Upload documents
* @param $uploadType
* @param bool $withoutMessage
* @return int
*/
public static function uploadDocuments($uploadType, $withoutMessage = false) {
if(isset($_SESSION[$uploadType]) && count($_SESSION[$uploadType]) > 0) {
$settings = UsersSettings::model()->findByAttributes(array(
'User_ID' => Yii::app()->user->userID,
));
//get default bank account
$condition = new CDbCriteria();
$condition->condition = "users_project_list.User_ID = '" . Yii::app()->user->userID . "'";
$condition->addCondition("users_project_list.Client_ID = '" . Yii::app()->user->clientID . "'");
$condition->addCondition("t.Account_Num_ID = '" . $settings->Default_Bank_Acct . "'");
$condition->join = "LEFT JOIN projects ON projects.Project_ID = t.Project_ID
LEFT JOIN users_project_list ON users_project_list.Project_ID = t.Project_ID";
$bankAcct = BankAcctNums::model()->with('client.company', 'project')->find($condition);
$defaultBankAcct = 0;
if ($bankAcct) {
$defaultBankAcct = $settings->Default_Bank_Acct;
}
//get user to send email
$person_to_email = false;
if (Yii::app()->user->id != 'user' && Yii::app()->user->id != 'single_user') {
$person_to_email = Users::model()->with('person')->findByPk(Yii::app()->user->userID);
} else {
$condition = new CDbCriteria();
$condition->join = "LEFT JOIN users_client_list ON users_client_list.User_ID = t.User_ID";
$condition->addInCondition('users_client_list.User_Type', array(UsersClientList::APPROVER, UsersClientList::PROCESSOR, UsersClientList::CLIENT_ADMIN));
$condition->addInCondition('t.User_Type', array(Users::ADMIN, Users::DB_ADMIN, Users::DATA_ENTRY_CLERK), "OR");
$condition->addCondition("users_client_list.Client_ID = '" . Yii::app()->user->clientID . "'");
$person_to_email = Users::model()->with('person')->find($condition);
}
foreach ($_SESSION[$uploadType] as $key => $current_upload_file) {
// check fed id
if ($current_upload_file['doctype'] == self::W9) {
if (!preg_match('/^(\d{2}\-\d{7})|(\d{3}\-\d{2}\-\d{4})|(IN[-]\d{6})|(T0[-]\d{7})$/', $current_upload_file['fed_id'])) {
return 2;
}
}
}
// insert documents into DB
foreach ($_SESSION[$uploadType] as $key => $current_upload_file) {
if (file_exists($current_upload_file['filepath'])) {
// create document
$document = new Documents();
$document->Document_Type = $current_upload_file['doctype'];
$document->User_ID = Yii::app()->user->userID;
$document->Client_ID = Yii::app()->user->clientID;
$document->Project_ID = Yii::app()->user->projectID;
$document->Created = date("Y-m-d H:i:s");
$document->save();
$new_doc_id=$document->Document_ID;
Audits::LogAction($document->Document_ID ,Audits::ACTION_UPLOAD);
// insert image
$image = new Images();
$imageData = addslashes(fread(fopen($current_upload_file['filepath'],"rb"),filesize($current_upload_file['filepath'])));
//$imageData = FileModification::ImageToPdfByFilePath($current_upload_file['filepath']);
$image->Document_ID = $document->Document_ID;
$image->Img = $imageData;
$image->File_Name = $current_upload_file['name'];
$image->Mime_Type = $current_upload_file['mimetype'];
$image->File_Hash = sha1_file($current_upload_file['filepath']);
$image->File_Size = intval(filesize($current_upload_file['filepath']));
$image->Pages_Count = FileModification::calculatePagesByPath($current_upload_file['filepath']);
$image->save();
$infile = @file_get_contents($current_upload_file['filepath'], FILE_BINARY);
if (($current_upload_file['mimetype'] == 'application/pdf' && $image->findPdfText($infile) == '')
|| $current_upload_file['mimetype'] != 'application/pdf') {
Documents::crateDocumentThumbnail($current_upload_file['filepath'], 'thumbs', $current_upload_file['mimetype'], $document->Document_ID, 80);
}
// delete file from temporary catalog and from cache table
//unlink($current_upload_file['filepath']);
FileCache::deleteBothFromCacheById($current_upload_file['file_id']);
if ($current_upload_file['doctype'] == self::W9) {
// if document is W9
// get additional fields
$fedId = trim($current_upload_file['fed_id']);
$newCompanyName = trim($current_upload_file['company_name']);
// get company info
$company = Companies::model()->with('client')->findByAttributes(array(
'Company_Fed_ID' => $fedId,
//.........这里部分代码省略.........
示例2: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Documents();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Documents'])) {
$model->attributes = $_POST['Documents'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例3: doAction
/**
* @param $key
* @param $value
* @param $context \Workflow\VTEntity
* @return array|void
*/
public function doAction($configuration, $filepath, $filename, $context, $targetRecordIds = array())
{
$adb = \PearDatabase::getInstance();
require_once 'modules/Documents/Documents.php';
$focus = new \Documents();
$focus->parentid = $context->getId();
$docTitle = $configuration["title"];
$docDescr = nl2br($configuration["description"]);
$docTitle = \Workflow\VTTemplate::parse($docTitle, $context);
$docDescr = \Workflow\VTTemplate::parse($docDescr, $context);
$focus->column_fields['notes_title'] = $docTitle;
$focus->column_fields['assigned_user_id'] = $context->get('assigned_user_id');
$focus->column_fields['filename'] = $filename;
$focus->column_fields['notecontent'] = $docDescr;
$focus->column_fields['filetype'] = 'application/pdf';
$focus->column_fields['filesize'] = filesize($filepath);
$focus->column_fields['filelocationtype'] = 'I';
$focus->column_fields['fileversion'] = '';
$focus->column_fields['filestatus'] = 'on';
$focus->column_fields['folderid'] = $configuration["folderid"];
$focus->save('Documents');
$upload_file_path = decideFilePath();
$date_var = date("Y-m-d H:i:s");
$next_id = $adb->getUniqueID("vtiger_crmentity");
copy($filepath, $upload_file_path . $next_id . "_" . $filename);
$sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?, ?, ?, ?, ?, ?, ?)";
$params1 = array($next_id, $context->get('assigned_user_id'), $context->get('assigned_user_id'), "Documents Attachment", 'Documents Attachment', date("Y-m-d H:i:s"), date("Y-m-d H:i:s"));
$adb->pquery($sql1, $params1);
$filetype = "application/octet-stream";
$sql2 = "insert into vtiger_attachments(attachmentsid, name, description, type, path) values(?, ?, ?, ?, ?)";
$params2 = array($next_id, $filename, $docDescr, $filetype, $upload_file_path);
$adb->pquery($sql2, $params2, true);
$sql3 = 'insert into vtiger_seattachmentsrel values(?,?)';
$adb->pquery($sql3, array($focus->id, $next_id));
if ($configuration["relation"] === "1") {
foreach ($targetRecordIds as $id) {
$sql = "INSERT INTO vtiger_senotesrel SET crmid = " . $id . ", notesid = " . $focus->id;
$adb->query($sql);
}
} else {
$sql = "DELETE FROM vtiger_senotesrel WHERE crmid = " . $context->getId() . " AND notesid = " . $focus->id;
$adb->query($sql);
}
$newContext = \Workflow\VTEntity::getForId($focus->id, "Documents");
if ($configuration['workflowid'] !== "") {
$objWorkflow = new \Workflow\Main($configuration['workflowid'], false, $context->getUser());
$objWorkflow->setContext($newContext);
$objWorkflow->isSubWorkflow(true);
$objWorkflow->start();
}
}
示例4: actionCreate
public function actionCreate()
{
$model = new Documents();
$flag1 = false;
if (!empty($_POST)) {
for ($i = 0; $i < count($_POST['Documents']['category_document_id']); $i++) {
$model = new Documents();
$flag = false;
$model->name = $_POST['Documents']['name'][$i];
$model->category_document_id = $_POST['Documents']['category_document_id'][$i];
$model->created = time();
$model->type_document = 1;
if ($_FILES['Documents']['error']['filename'][$i] == 0) {
$tmp_name = $_FILES['Documents']['tmp_name']['filename'][$i];
$model->size = $_FILES['Documents']['size']['filename'][$i];
$filename = $_FILES['Documents']['name']['filename'][$i];
$filename = explode(".", $filename);
$model->filename = $filename[count($filename) - 2] . "." . end($filename);
$model->type = end($filename);
$filenameMd5 = md5(uniqid()) . '.' . $model->type;
$model->md5name = $filenameMd5;
$filenames_path = Yii::getPathOfAlias('webroot') . '/upload/documents/' . $filenameMd5;
$flag = true;
}
if ($flag == true) {
if ($model->save()) {
move_uploaded_file($tmp_name, $filenames_path);
$flag1 = true;
}
}
}
if ($flag1 == true) {
Yii::app()->user->setFlash('success', translate('Thêm thành công.'));
$this->redirect(PIUrl::createUrl('/admin/documents/index'));
} else {
Yii::app()->user->setFlash('error', translate('Thêm không thành công.'));
$this->redirect(PIUrl::createUrl('/admin/documents/create'));
}
}
$dataCategories = categoriesDocuments::model()->getCategoriesDocument();
$this->render('create', array('model' => $model, 'dataCategory' => $dataCategories));
}
示例5: add_ticket_attachment
/** function to add attachment for a ticket ie., the passed contents will be write in a file and the details will be stored in database
* @param array $input_array - array which contains the following values
=> int $id - customer ie., contact id
int $sessionid - session id
int $ticketid - ticket id
string $filename - file name to be attached with the ticket
string $filetype - file type
int $filesize - file size
string $filecontents - file contents as base64 encoded format
* return void
*/
function add_ticket_attachment($input_array)
{
$adb = PearDatabase::getInstance();
$log = vglobal('log');
global $root_directory, $upload_badext;
$log->debug("Entering customer portal function add_ticket_attachment");
$adb->println("INPUT ARRAY for the function add_ticket_attachment");
$adb->println($input_array);
$id = $input_array['id'];
$sessionid = $input_array['sessionid'];
$ticketid = $input_array['ticketid'];
$filename = $input_array['filename'];
$filetype = $input_array['filetype'];
$filesize = $input_array['filesize'];
$filecontents = $input_array['filecontents'];
if (!validateSession($id, $sessionid)) {
return null;
}
//decide the file path where we should upload the file in the server
$upload_filepath = decideFilePath();
$attachmentid = $adb->getUniqueID("vtiger_crmentity");
//fix for space in file name
$filename = sanitizeUploadFileName($filename, $upload_badext);
$new_filename = $attachmentid . '_' . $filename;
$data = base64_decode($filecontents);
$description = 'CustomerPortal Attachment';
//write a file with the passed content
$handle = @fopen($upload_filepath . $new_filename, 'w');
fputs($handle, $data);
fclose($handle);
//Now store this file information in db and relate with the ticket
$date_var = $adb->formatDate(date('Y-m-d H:i:s'), true);
$crmquery = "insert into vtiger_crmentity (crmid,setype,description,createdtime) values(?,?,?,?)";
$crmresult = $adb->pquery($crmquery, array($attachmentid, 'HelpDesk Attachment', $description, $date_var));
$attachmentquery = "insert into vtiger_attachments(attachmentsid,name,description,type,path) values(?,?,?,?,?)";
$attachmentreulst = $adb->pquery($attachmentquery, array($attachmentid, $filename, $description, $filetype, $upload_filepath));
$relatedquery = "insert into vtiger_seattachmentsrel values(?,?)";
$relatedresult = $adb->pquery($relatedquery, array($ticketid, $attachmentid));
$user_id = getDefaultAssigneeId();
require_once 'modules/Documents/Documents.php';
$focus = new Documents();
$focus->column_fields['notes_title'] = $filename;
$focus->column_fields['filename'] = $filename;
$focus->column_fields['filetype'] = $filetype;
$focus->column_fields['filesize'] = $filesize;
$focus->column_fields['filelocationtype'] = 'I';
$focus->column_fields['filedownloadcount'] = 0;
$focus->column_fields['filestatus'] = 1;
$focus->column_fields['assigned_user_id'] = $user_id;
$focus->column_fields['folderid'] = 1;
$focus->parent_id = $ticketid;
$focus->save('Documents');
$related_doc = 'insert into vtiger_seattachmentsrel values (?,?)';
$res = $adb->pquery($related_doc, array($focus->id, $attachmentid));
$tic_doc = 'insert into vtiger_senotesrel values(?,?)';
$res = $adb->pquery($tic_doc, array($ticketid, $focus->id));
$log->debug("Exiting customer portal function add_ticket_attachment");
}
示例6: create_note_from_webform
function create_note_from_webform($username, $sessionid, $subject, $desc)
{
global $log;
global $adb;
global $current_user;
if (!validateSession($username, $sessionid)) {
return null;
}
require_once "modules/Users/Users.php";
$seed_user = new Users();
$user_id = $seed_user->retrieve_user_id($username);
$current_user = $seed_user;
$current_user->retrieve_entity_info($user_id, 'Users');
$adb->println("Create New Document from Web Form - Starts");
require_once "modules/Documents/Documents.php";
$focus = new Documents();
if (isPermitted("Documents", "EditView") == "yes") {
$focus->column_fields['notes_title'] = $subject;
$focus->column_fields['notecontent'] = $desc;
$focus->save("Documents");
$focus->retrieve_entity_info($focus->id, "Documents");
$adb->println("Create New Document from Web Form - Ends");
if ($focus->id != '') {
return 'Document added successfully.';
} else {
return "Document creation failed. Try again";
}
} else {
return $accessDenied;
}
}
示例7: handleTask
/**
* @param $context VTEntity
*/
public function handleTask(&$context)
{
if (!getTabid('PDFMaker') || !vtlib_isModuleActive('PDFMaker')) {
return 'yes';
}
global $adb, $current_user, $log, $root_directory;
// PDFMaker greift auf Datenbank zurück. Daher zuerst speichern!
$context->save();
$userId = $context->get('assigned_user_id');
if ($userId === null) {
$userId = vtws_getWebserviceEntityId('Users', 1);
}
$moduleName = $context->getModuleName();
$id = $context->getId();
list($id2, $assigned_user_id) = explode("x", $userId);
$parentid = $id;
require_once 'modules/Documents/Documents.php';
$focus = new \Documents();
$focus->parentid = $parentid;
$modFocus = $context->getInternalObject();
$templateid = $this->template;
$this->folder = 1;
$foldername = $adb->getOne("SELECT foldername FROM vtiger_attachmentsfolder WHERE folderid='" . $this->folder . "'", 0, "foldername");
$fieldname = $adb->getOne("SELECT fieldname FROM vtiger_field WHERE uitype=4 AND tabid=" . getTabId($moduleName), 0, "fieldname");
/* new PDFMaker Routine */
$PDFMaker = new PDFMaker_PDFMaker_Model();
if (isset($modFocus->column_fields[$fieldname]) && $modFocus->column_fields[$fieldname] != "") {
$file_name = $PDFMaker->generate_cool_uri($modFocus->column_fields[$fieldname]) . ".pdf";
} else {
$file_name = generate_cool_uri($foldername . "_" . $templateid . $focus->parentid . date("ymdHi")) . ".pdf";
}
$this->addStat("Attach Document '" . $file_name . "'");
$docTitle = $this->get("documenttitle", $context);
$docDescr = $this->get("documentdescr", $context);
$focus->column_fields['notes_title'] = $docTitle;
$focus->column_fields['assigned_user_id'] = $assigned_user_id;
$focus->column_fields['filename'] = $file_name;
$focus->column_fields['notecontent'] = $docDescr;
$focus->column_fields['filetype'] = 'application/pdf';
$focus->column_fields['filesize'] = '';
$focus->column_fields['filelocationtype'] = 'I';
$focus->column_fields['fileversion'] = '';
$focus->column_fields['filestatus'] = 'on';
$focus->column_fields['folderid'] = $this->get("folderid");
$focus->save('Documents');
$language = $current_user->language;
$request = $_REQUEST;
$_REQUEST['search'] = true;
$_REQUEST['submode'] = true;
if ($current_user->is_admin != "on") {
$useUser = Users::getActiveAdminUser();
} else {
$useUser = $current_user;
}
$oldCurrentUser = $current_user;
$current_user = $useUser;
$dummyRequest = new Vtiger_Request(array());
$PDFMaker->createPDFAndSaveFile($dummyRequest, $this->get("template"), $focus, $modFocus, $file_name, $this->getModuleName(), $language);
$current_user = $oldCurrentUser;
$_REQUEST = $request;
/* new PDFMaker Routine */
$overwriteFilename = $this->get("filename", $context);
if ($overwriteFilename != -1 && !empty($overwriteFilename)) {
global $root_directory;
$sql = "SELECT attachmentsid FROM vtiger_seattachmentsrel WHERE crmid = " . $focus->id . " ORDER BY attachmentsid DESC LIMIT 1";
$result = $adb->query($sql);
if ($adb->num_rows($result) > 0) {
$attachmentsid = $adb->query_result($result, 0, "attachmentsid");
$attRst = $adb->query("SELECT * FROM vtiger_attachments WHERE attachmentsid = " . $attachmentsid);
$attachment = $adb->fetchByAssoc($attRst);
$oldFilename = $root_directory . "/" . $attachment["path"] . $attachmentsid . "_" . $attachment["name"];
$newFilename = $root_directory . "/" . $attachment["path"] . $attachmentsid . "_" . $overwriteFilename;
@rename($oldFilename, $newFilename);
$adb->pquery("UPDATE vtiger_attachments SET name = ? WHERE attachmentsid = " . $attachmentsid, array($overwriteFilename));
$adb->pquery("UPDATE vtiger_notes SET filename = ? WHERE notesid = " . $focus->id, array($overwriteFilename));
}
$file_name = $foldername . "_" . $overwriteFilename;
}
$_REQUEST = $request;
if ($this->get("createrel") === "1") {
$sql = "INSERT INTO vtiger_senotesrel SET crmid = " . $context->getId() . ", notesid = " . $focus->id;
$adb->query($sql);
} else {
$sql = "DELETE FROM vtiger_senotesrel WHERE crmid = " . $context->getId() . " AND notesid = " . $focus->id;
$adb->query($sql);
}
$newContext = \Workflow\VTEntity::getForId($focus->id, "Documents");
if ($this->get("workflow") !== "") {
$objWorkflow = new \Workflow\Main($this->get("workflow"), false, $context->getUser());
$objWorkflow->setContext($newContext);
$objWorkflow->isSubWorkflow(true);
$objWorkflow->start();
}
$context->setEnvironment("new_record_id", $newContext->getWsId(), $this);
return "yes";
}
示例8: array
$filestatus = "0";
}
$noteid_query = $adb->pquery("SELECT notesid FROM vtiger_notes WHERE notesid = ?", array($crmid));
if ($adb->num_rows($noteid_query) > 0) {
$notesid = $adb->query_result($noteid_query, 0, "notesid");
ExecuteQuery("update vtiger_notes set folderid = 1,filestatus='{$filestatus}',filelocationtype='I',filedownloadcount=0,fileversion='',filetype='" . $filetype . "',filesize='" . $filesize . "',filename='" . $filename . "' where notesid = " . $notesid);
} else {
require_once "modules/Documents/Documents.php";
$notes_obj = new Documents();
if ($attch_sub == '') {
$attch_sub = $filename;
}
$notes_obj->column_fields['notes_title'] = decode_html($attch_sub);
$notes_obj->column_fields['notecontent'] = decode_html($description);
$notes_obj->column_fields['assigned_user_id'] = 1;
$notes_obj->save("Documents");
$notesid = $notes_obj->id;
ExecuteQuery("Update vtiger_notes set folderid=1,filedownloadcount=0, filestatus='{$filestatus}', fileversion='', filesize = '{$filesize}', filetype = '{$filetype}' , filelocationtype = 'I', filename = '{$filename}' where notesid = {$notesid}");
ExecuteQuery("INSERT INTO vtiger_senotesrel VALUES({$crmid},{$notesid})");
ExecuteQuery("INSERT INTO vtiger_seattachmentsrel VALUES({$notesid},{$attachmentid})");
}
}
} else {
ExecuteQuery("update vtiger_notes set folderid=1, filestatus=1,filelocationtype='',filedownloadcount='',fileversion='',filetype='',filesize='',filename='' where notesid = " . $notesid);
}
}
}
$fieldid = array();
for ($i = 0; $i < 8; $i++) {
$fieldid[$i] = $adb->getUniqueID("vtiger_field");
}
示例9: createNewFromSessionData
public static function createNewFromSessionData($current_upload_file,$client){
if (file_exists($current_upload_file['filepath'])) {
// create document
$document = new Documents();
$document->Document_Type = $current_upload_file['doctype'];
$document->User_ID = Yii::app()->user->userID;
$document->Client_ID = Yii::app()->user->clientID;
$document->Project_ID = Yii::app()->user->projectID;
$document->Created = date("Y-m-d H:i:s");
$document->save();
$new_doc_id=$document->Document_ID;
Audits::LogAction($document->Document_ID ,Audits::ACTION_UPLOAD);
// insert image
$image = new Images();
$imageData = addslashes(fread(fopen($current_upload_file['filepath'],"rb"),filesize($current_upload_file['filepath'])));
//$imageData = FileModification::ImageToPdfByFilePath($current_upload_file['filepath']);
$image->Document_ID = $document->Document_ID;
$image->Img = $imageData;
$image->File_Name = $current_upload_file['name'];
$image->Mime_Type = $current_upload_file['mimetype'];
$image->File_Hash = sha1_file($current_upload_file['filepath']);
$image->File_Size = intval(filesize($current_upload_file['filepath']));
$image->Pages_Count = FileModification::calculatePagesByPath($current_upload_file['filepath']);
$image->save();
$infile = @file_get_contents($current_upload_file['filepath'], FILE_BINARY);
if (($current_upload_file['mimetype'] == 'application/pdf' && $image->findPdfText($infile) == '')
|| $current_upload_file['mimetype'] != 'application/pdf') {
Documents::crateDocumentThumbnail($current_upload_file['filepath'], 'thumbs', $current_upload_file['mimetype'], $document->Document_ID, 80);
}
// delete file from temporary catalog
unlink($current_upload_file['filepath']);
}
$fedId = trim($current_upload_file['fed_id']);
$newCompanyName = trim($current_upload_file['company_name']);
// get company info
$company = Companies::model()->with('client')->findByAttributes(array(
'Company_Fed_ID' => $fedId,
));
// create w9
$W9 = new W9();
$W9->Document_ID = $document->Document_ID;
$W9->W9_Owner_ID = Yii::app()->user->clientID;
$W9->Creator_ID = Yii::app()->user->userID;
$W9->Business_Name = trim($current_upload_file['bus_name']);
$W9->Tax_Class = trim($current_upload_file['tax_name']);
// get user info
$user = Users::model()->with('person')->findByPk(Yii::app()->user->userID);
if ($company) {
// if company exisits
$client = $company->client;
//fill created company with dataentry values from session
Companies::fillWithSessionDataEntry($company,$current_upload_file);
$existingW9 = W9::model()->findByAttributes(array(
'Client_ID' => $client->Client_ID,
'W9_Owner_ID' => Yii::app()->user->clientID,
));
if ($existingW9) {
$W9->Revision_ID = -1;
} else {
$W9->Revision_ID = 0;
}
$vendor = Vendors::model()->findByAttributes(array(
'Client_Client_ID' => Yii::app()->user->clientID,
'Vendor_Client_ID' => $client->Client_ID,
));
if (isset($vendor->Active_Relationship) && $vendor->Active_Relationship == Vendors::NOT_ACTIVE_RELATIONSHIP) {
$vendor->Active_Relationship = Vendors::ACTIVE_RELATIONSHIP;
$vendor->save();
} else if (!$vendor && Yii::app()->user->clientID != 0 && Yii::app()->user->clientID != $client->Client_ID) {
$vendor = new Vendors();
$vendor->Vendor_ID_Shortcut = '';
$vendor->Vendor_Client_ID = $client->Client_ID;
$vendor->Client_Client_ID = Yii::app()->user->clientID;
$vendor->Vendor_Name_Checkprint = '';
$vendor->Vendor_1099 = '';
$vendor->Vendor_Default_GL = '';
$vendor->Vendor_Default_GL_Note = '';
$vendor->Vendor_Note_General = '';
$vendor->save();
}
} else {
//if company does not exists, create new company
//.........这里部分代码省略.........
示例10: createDocument
/**
* Used to create Documents
* @global Users $current_user
* @global PearDataBase $adb
* @global String $currentModule
*/
function createDocument()
{
global $current_user, $adb, $currentModule;
if (!MailManager::checkModuleWriteAccessForCurrentUser('Documents')) {
$errorMessage = getTranslatedString('LBL_WRITE_ACCESS_FOR', $currentModule) . " " . getTranslatedString('Documents') . " " . getTranslatedString('LBL_MODULE_DENIED', $currentModule);
return array('success' => true, 'error' => $errorMessage);
}
require_once 'data/CRMEntity.php';
$document = CRMEntity::getInstance('Documents');
$attachid = $this->saveAttachment();
if ($attachid !== false) {
// Create document record
$document = new Documents();
$document->column_fields['notes_title'] = $this->getName();
$document->column_fields['filename'] = $this->getName();
$document->column_fields['filestatus'] = 1;
$document->column_fields['filelocationtype'] = 'I';
$document->column_fields['folderid'] = 1;
$document->column_fields['filesize'] = $this->getSize();
$document->column_fields['assigned_user_id'] = $current_user->id;
$document->save('Documents');
// Link file attached to document
$adb->pquery("INSERT INTO vtiger_seattachmentsrel(crmid, attachmentsid) VALUES(?,?)", array($document->id, $attachid));
return array('success' => true, 'docid' => $document->id, 'attachid' => $attachid);
}
return false;
}
示例11: add_attachment_to_contact
function add_attachment_to_contact($cid, $email, $emailid)
{
// add vtiger_attachments to contact
global $adb, $current_user, $default_charset;
for ($j = 0; $j < 2; $j++) {
if ($j == 0) {
$attachments = $email->downloadAttachments();
} else {
$attachments = $email->downloadInlineAttachments();
}
$upload_filepath = decideFilePath();
for ($i = 0, $num_files = count($attachments); $i < $num_files; $i++) {
$current_id = $adb->getUniqueID("vtiger_crmentity");
$date_var = $adb->formatDate(date('Y-m-d H:i:s'), true);
$filename = preg_replace("/[ ()-]+/", "_", $attachments[$i]["filename"]);
preg_match_all('/=\\?([^\\?]+)\\?([^\\?]+)\\?([^\\?]+)\\?=/', $filename, $matches);
$totalmatches = count($matches[0]);
for ($index = 0; $index < $totalmatches; ++$index) {
$charset = $matches[1][$index];
$encoding = strtoupper($matches[2][$index]);
$data = $matches[3][$index];
if ($encoding == 'B') {
$filename = base64_decode($data);
} else {
if ($encoding == 'Q') {
$filename = quoted_printable_decode($data);
}
}
$filename = iconv(str_replace('_', '-', $charset), $default_charset, $filename);
}
$saveasfile = $upload_filepath . '/' . $current_id . '_' . $filename;
$filetype = MailAttachmentMIME::detect($saveasfile);
$filesize = $attachments[$i]["filesize"];
$query = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?,?,?,?,?,?,?)";
$qparams = array($current_id, $current_user->id, $current_user->id, 'Contacts Attachment', 'Uploaded from webmail during qualification', $date_var, $date_var);
$result = $adb->pquery($query, $qparams);
$sql = "insert into vtiger_attachments (attachmentsid,name,description,type,path) values(?,?,?,?,?)";
$params = array($current_id, $filename, 'Uploaded ' . $filename . ' from webmail', $filetype, $upload_filepath);
$result = $adb->pquery($sql, $params);
if (!empty($result)) {
// Create document record
$document = new Documents();
$document->column_fields['notes_title'] = $filename;
$document->column_fields['filename'] = $filename;
$document->column_fields['filesize'] = $filesize;
$document->column_fields['filetype'] = $filetype;
$document->column_fields['filestatus'] = 1;
$document->column_fields['filelocationtype'] = 'I';
$document->column_fields['folderid'] = 1;
// Default Folder
$document->column_fields['assigned_user_id'] = $current_user->id;
$document->save('Documents');
$sql1 = "insert into vtiger_senotesrel values(?,?)";
$params1 = array($cid, $document->id);
$result = $adb->pquery($sql1, $params1);
$sql1 = "insert into vtiger_seattachmentsrel values(?,?)";
$params1 = array($document->id, $current_id);
$result = $adb->pquery($sql1, $params1);
$sql1 = "insert into vtiger_seattachmentsrel values(?,?)";
$params1 = array($emailid, $current_id);
$result = $adb->pquery($sql1, $params1);
}
//we have to add attachmentsid_ as prefix for the filename
$move_filename = $upload_filepath . '/' . $current_id . '_' . $filename;
$fp = fopen($move_filename, "w") or die("Can't open file");
fputs($fp, base64_decode($attachments[$i]["filedata"]));
fclose($fp);
}
}
}
示例12: foreach
/**
* Save attachments from the email and add it to the module record.
*/
function __SaveAttachements($mailrecord, $basemodule, $basefocus)
{
global $adb;
// If there is no attachments return
if (!$mailrecord->_attachments) {
return;
}
$userid = $basefocus->column_fields['assigned_user_id'];
$setype = "{$basemodule} Attachment";
$date_var = $adb->formatDate(date('YmdHis'), true);
foreach ($mailrecord->_attachments as $filename => $filecontent) {
$attachid = $adb->getUniqueId('vtiger_crmentity');
$description = $filename;
$usetime = $adb->formatDate($date_var, true);
$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));
$issaved = $this->__SaveAttachmentFile($attachid, $filename, $filecontent);
if ($issaved) {
// Create document record
$document = new Documents();
$document->column_fields['notes_title'] = $filename;
$document->column_fields['filename'] = $filename;
$document->column_fields['filestatus'] = 1;
$document->column_fields['filelocationtype'] = 'I';
$document->column_fields['folderid'] = 1;
// Default Folder
$document->column_fields['assigned_user_id'] = $userid;
$document->save('Documents');
// Link file attached to document
$adb->pquery("INSERT INTO vtiger_seattachmentsrel(crmid, attachmentsid) VALUES(?,?)", array($document->id, $attachid));
// Link document to base record
$adb->pquery("INSERT INTO vtiger_senotesrel(crmid, notesid) VALUES(?,?)", array($basefocus->id, $document->id));
// Link document to Parent entity - Account/Contact/...
list($eid, $junk) = explode('@', $basefocus->column_fields['parent_id']);
$adb->pquery("INSERT INTO vtiger_senotesrel(crmid, notesid) VALUES(?,?)", array($eid, $document->id));
// Link Attachement to the Email
$adb->pquery("INSERT INTO vtiger_seattachmentsrel(crmid, attachmentsid) VALUES(?,?)", array($basefocus->id, $attachid));
}
}
}
示例13: loadAndSave
public static function loadAndSave($personid, $objarr)
{
foreach ($objarr as $item) {
$val = (object) $item;
if ($val->id_Type == 4) {
$doc = new Documents();
$doc->scenario = "FULLINPUT";
$doc->PersonID = $personid;
$doc->TypeID = $val->id_Type;
$doc->edboID = $val->id_Document;
$doc->AtestatValue = $val->attestatValue;
$doc->Numbers = $val->number;
$doc->Series = $val->series;
$doc->DateGet = date("d.m.Y", mktime(0, 0, 0, $val->dateGet['month'] + 1, $val->dateGet['dayOfMonth'], $val->dateGet['year']));
$doc->ZNOPin = $val->znoPin;
$doc->Issued = $val->issued;
if ($val->dateGet['year'] < date("Y")) {
Yii::log("Пропущено сертификат {$doc->Numbers} " . $val->dateGet['year'] . " года!");
continue;
}
if ($doc->save() && !empty($val->subjects)) {
foreach ($val->subjects as $valstr) {
$item = (object) $valstr;
$subj = new Documentsubject();
$subj->DateGet = $doc->DateGet;
$subj->edboID = $item->id_DocumentSubject;
$subj->DocumentID = $doc->idDocuments;
$subj->SubjectID = $item->id_Subject;
$subj->SubjectValue = $item->subjectValue;
$subj->save();
}
}
} else {
if ($val->id_Type == 11 || $val->id_Type == 12 || $val->id_Type == 13 || $val->id_Type == 2) {
$exdoc = null;
try {
if (empty($exdoc)) {
$doc = new Documents();
//$doc->scenario = "FULLINPUT";
$doc->PersonID = $personid;
$doc->TypeID = $val->id_Type;
$doc->edboID = $val->id_Document;
$doc->AtestatValue = $val->attestatValue;
$doc->Numbers = $val->number;
$doc->Series = $val->series;
$doc->DateGet = date("d.m.Y", mktime(0, 0, 0, $val->dateGet['month'] + 1, $val->dateGet['dayOfMonth'], $val->dateGet['year']));
//$doc->ZNOPin = $val->znoPin;
$doc->Issued = $val->issued;
if (!$doc->save()) {
throw new Exception(print_r($doc->getErrors(), 1));
}
}
} catch (Exception $exc) {
Yii::log($exc->getMessage());
}
} else {
if (Yii::app()->user->checkAccess("asEDBOReqOperator")) {
try {
if (empty($exdoc)) {
$doc = new Documents();
$doc->scenario = "FULLINPUT";
$doc->PersonID = $personid;
$doc->TypeID = $val->id_Type;
$doc->edboID = $val->id_Document;
$doc->AtestatValue = $val->attestatValue;
$doc->Numbers = $val->number;
$doc->Series = $val->series;
$doc->DateGet = date("d.m.Y", mktime(0, 0, 0, $val->dateGet['month'] + 1, $val->dateGet['dayOfMonth'], $val->dateGet['year']));
//$doc->ZNOPin = $val->znoPin;
$doc->Issued = $val->issued;
if (!$doc->save()) {
throw new Exception(print_r($doc->getErrors()));
}
}
} catch (Exception $exc) {
Yii::log($exc->getMessage());
}
}
}
}
}
}
示例14: actionCreate
/**
* Creates a new model.
*/
public function actionCreate()
{
// create Comments Object
$model = new Comments();
// if Comments form exist
if (isset($_POST['Comments'])) {
// set form elements to Comments model attributes
$model->attributes = $_POST['Comments'];
$module = Modules::model()->find(array('condition' => 't.module_name = :module_name', 'params' => array(':module_name' => $model->module_id)));
// set module_id finded to model
$model->module_id = $module->module_id;
$project = Yii::app()->user->getState('project_selected');
$model->project_id = $project;
// validate and save
if ($model->save()) {
// create an instance of file uploaded
$image = CUploadedFile::getInstancesByName('Comment');
// if file upload exist
if (count($image > 0)) {
// for each file uploaded
for ($i = 0; $i < count($image); $i++) {
// create an Document object
$modeldocs = new Documents();
$modeldocs->image = $image[$i];
if (!$modeldocs->image->getError()) {
// name is formed by date(day+month+year+hour+minutes+seconds+dayofyear+microtime())
$this->tmpFileName = str_replace(" ", "", date('dmYHis-z-') . microtime());
// set the extension file uploaded
$extension = $modeldocs->image->getExtensionName();
// if no error saving file
if ($modeldocs->image->saveAs(self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension)) {
$modeldocs->project_id = $project;
$modeldocs->document_name = substr($modeldocs->image->getName(), 0, 30);
$modeldocs->document_description = $model->comment_text;
$modeldocs->document_path = self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension;
$modeldocs->document_revision = '1';
$modeldocs->document_uploadDate = date("Y-m-d");
$modeldocs->document_type = $modeldocs->image->getType();
$modeldocs->document_baseRevision = date('dmYHis');
$modeldocs->user_id = Yii::app()->user->id;
$modeldocs->comment_id = $model->primaryKey;
// save file uploaded as document
if ($modeldocs->save()) {
Yii::app()->user->setFlash('CommentMessageSuccess', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadOk'));
} else {
Yii::app()->user->setFlash('CommentMessage', $modeldocs->getErrors());
}
} else {
Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadError'));
}
} else {
Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->error . " " . Yii::t('comments', 'UploadCheckErrors'));
}
}
}
// save log
$attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CommentPosted', 'log_resourceid' => $model->comment_resourceid, 'log_type' => Logs::LOG_COMMENTED, 'log_commentid' => $model->primaryKey, 'user_id' => Yii::app()->user->id, 'module_id' => $module->module_name, 'project_id' => $project);
Logs::model()->saveLog($attributes);
// find project managers to sent comment via mail
$recipientsList = array();
$ProjectManagers = Projects::model()->findManagersByProject($project);
$managersArray = array();
foreach ($ProjectManagers as $manager) {
$managersArray['email'] = $manager->user_email;
$managersArray['name'] = $manager->CompleteName;
array_push($recipientsList, $managersArray);
}
// find task owners to send comment via mail
if ($module->module_name == 'tasks') {
$collaborators = Projects::model()->findAllUsersByProject($project);
$ColaboratorsArray = array();
foreach ($collaborators as $colaborator) {
$ColaboratorsArray['email'] = $colaborator->user_email;
$ColaboratorsArray['name'] = $colaborator->CompleteName;
// avoid to repeat email address
if (!in_array($ColaboratorsArray, $recipientsList)) {
array_push($recipientsList, $ColaboratorsArray);
}
}
}
// finding resource title
switch ($module->module_name) {
case "budgets":
$resourceModelTitle = Budgets::model()->findByPk($model->comment_resourceid)->budget_title;
break;
case "invoices":
$resourceModelTitle = Invoices::model()->findByPk($model->comment_resourceid)->invoice_number;
break;
case "expenses":
$resourceModelTitle = Expenses::model()->findByPk($model->comment_resourceid)->expense_name;
break;
case "documents":
$resourceModelTitle = Documents::model()->findByPk($model->comment_resourceid)->document_name;
break;
case "milestones":
$resourceModelTitle = Milestones::model()->findByPk($model->comment_resourceid)->milestone_title;
break;
//.........这里部分代码省略.........
示例15: actionCreate
public function actionCreate($personid, $type = "")
{
$model = new Documents("FULLINPUT");
$model->PersonID = $personid;
$valid = true;
$formtype = "other";
if (isset($_POST["Documents"])) {
$model->attributes = $_POST["Documents"];
switch ($model->type->IsEntrantDocument) {
case 2:
$formtype = "other";
break;
case 1:
if ($model->TypeID == 2 || $model->TypeID == 1 || $model->TypeID == 7 || $model->TypeID == 8) {
$formtype = "atestat";
} else {
$formtype = "diplom";
}
break;
default:
$formtype = "other";
}
if (empty($type)) {
$valid = $model->validate() && $valid;
if ($valid && $model->save()) {
//$person = Person::model()->findByPk($model->PersonID);
echo CJSON::encode(array("result" => "success", "data" => $this->renderPartial("//person/tabs/_doc", array('personid' => $model->PersonID), true)));
} else {
echo CJSON::encode(array("result" => "error", "data" => $this->renderPartial("_form_{$formtype}", array('model' => $model), true)));
}
Yii::app()->end();
} else {
echo CJSON::encode(array("result" => "success", "data" => $this->renderPartial("_form_{$formtype}", array('model' => $model), true)));
Yii::app()->end();
}
}
$this->renderPartial('_docModal', array('model' => $model, "formtype" => $formtype, true, true));
}