2015-12-19 20:23:57 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
G::LoadClass( "pmDrive" );
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class InputDocumentDrive
|
|
|
|
|
*/
|
|
|
|
|
class AppDocumentDrive
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var PMDrive $drive
|
|
|
|
|
*/
|
|
|
|
|
private $drive;
|
|
|
|
|
/**
|
|
|
|
|
* @var Application $app
|
|
|
|
|
*/
|
|
|
|
|
private $app;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Users $user
|
|
|
|
|
*/
|
|
|
|
|
private $user;
|
|
|
|
|
|
|
|
|
|
private $statusDrive;
|
2016-02-29 12:45:35 -04:00
|
|
|
private $usersEmail = '';
|
2015-12-19 20:23:57 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* InputDocumentDrive constructor.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->drive = new PMDrive();
|
2016-01-05 15:26:43 -04:00
|
|
|
$status = $this->drive->getServiceDriveStatus();
|
2015-12-19 20:23:57 -04:00
|
|
|
$status = !empty($status) ? ($status == 1 ? true : false): false;
|
2016-02-29 12:45:35 -04:00
|
|
|
$this->usersEmail = '';
|
2015-12-19 20:23:57 -04:00
|
|
|
$this->setStatusDrive($status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function getStatusDrive()
|
|
|
|
|
{
|
|
|
|
|
return $this->statusDrive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param boolen $statusDrive
|
|
|
|
|
*/
|
|
|
|
|
public function setStatusDrive($statusDrive)
|
|
|
|
|
{
|
|
|
|
|
$this->statusDrive = $statusDrive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function loadUser ($usrUid)
|
|
|
|
|
{
|
|
|
|
|
$this->user = new Users();
|
|
|
|
|
$this->user->load($usrUid);
|
|
|
|
|
$this->drive->setDriveUser($this->user->getUsrEmail());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function loadApplication ($appUid)
|
|
|
|
|
{
|
|
|
|
|
$this->app = new Application();
|
|
|
|
|
$this->app->Load($appUid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function existAppFolderDrive ()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
if ($this->app->getAppDriveFolderUid() == null) {
|
|
|
|
|
$process = new Process();
|
|
|
|
|
$process->setProUid($this->app->getProUid());
|
|
|
|
|
|
|
|
|
|
$result = $this->drive->createFolder(
|
|
|
|
|
$process->getProTitle() . ' - ' . G::LoadTranslation("ID_CASE") . ' #' . $this->app->getAppNumber(),
|
|
|
|
|
$this->drive->getFolderIdPMDrive($this->user->getUsrUid())
|
|
|
|
|
);
|
|
|
|
|
$this->app->setAppDriveFolderUid($result->id);
|
|
|
|
|
$this->app->update($this->app->toArray(BasePeer::TYPE_FIELDNAME));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
error_log('Error create folder Drive: ' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function permission ($appUid, $folderUid, $fileIdDrive)
|
|
|
|
|
{
|
|
|
|
|
$criteria = new Criteria('workflow');
|
|
|
|
|
$criteria->addSelectColumn(ApplicationPeer::PRO_UID);
|
|
|
|
|
$criteria->addSelectColumn(TaskUserPeer::TAS_UID);
|
|
|
|
|
$criteria->addSelectColumn(TaskUserPeer::USR_UID);
|
|
|
|
|
$criteria->addSelectColumn(TaskUserPeer::TU_RELATION);
|
|
|
|
|
|
|
|
|
|
$criteria->add(ApplicationPeer::APP_UID, $appUid);
|
|
|
|
|
$criteria->addJoin(ApplicationPeer::PRO_UID, TaskPeer::PRO_UID, Criteria::LEFT_JOIN);
|
|
|
|
|
$criteria->addJoin(TaskPeer::TAS_UID, TaskUserPeer::TAS_UID, Criteria::LEFT_JOIN);
|
|
|
|
|
|
|
|
|
|
$rs = ApplicationPeer::doSelectRS($criteria);
|
|
|
|
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
$userPermission = array();
|
|
|
|
|
$user = new Users();
|
|
|
|
|
|
|
|
|
|
while ($rs->next()) {
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
if ($row['TU_RELATION'] == 1) {
|
|
|
|
|
//users
|
|
|
|
|
$dataUser = $user->load($row['USR_UID']);
|
|
|
|
|
if (array_search($dataUser['USR_EMAIL'], $userPermission) === false) {
|
|
|
|
|
$objectPermissions = $this->getAllObjects($row['PRO_UID'], $appUid, $row['TAS_UID'],
|
|
|
|
|
$row['USR_UID']);
|
|
|
|
|
$userPermission[] = $dataUser['USR_EMAIL'];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//Groups
|
|
|
|
|
$criteria = new Criteria('workflow');
|
|
|
|
|
$criteria->addSelectColumn(UsersPeer::USR_EMAIL);
|
|
|
|
|
$criteria->addSelectColumn(UsersPeer::USR_UID);
|
|
|
|
|
$criteria->add(GroupUserPeer::GRP_UID, $row['USR_UID']);
|
|
|
|
|
$criteria->addJoin(GroupUserPeer::USR_UID, UsersPeer::USR_UID, Criteria::LEFT_JOIN);
|
|
|
|
|
|
|
|
|
|
$rsGroup = AppDelegationPeer::doSelectRS($criteria);
|
|
|
|
|
$rsGroup->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
while ($rsGroup->next()) {
|
|
|
|
|
$aRow = $rsGroup->getRow();
|
|
|
|
|
if (array_search($aRow['USR_EMAIL'], $userPermission) === false) {
|
|
|
|
|
$objectPermissions = $this->getAllObjects($row['PRO_UID'], $appUid,
|
|
|
|
|
$row['TAS_UID'], $aRow['USR_UID']);
|
|
|
|
|
$userPermission[] = $aRow['USR_EMAIL'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$userPermission = array_unique($userPermission);
|
|
|
|
|
|
|
|
|
|
foreach ($userPermission as $key => $val) {
|
|
|
|
|
$this->drive->setPermission($folderUid, $val, 'user', 'writer');
|
|
|
|
|
$this->drive->setPermission($fileIdDrive, $val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-29 12:45:35 -04:00
|
|
|
public function addUserEmail ($email)
|
2015-12-19 20:23:57 -04:00
|
|
|
{
|
|
|
|
|
if (empty($email)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-02-29 12:45:35 -04:00
|
|
|
if ($this->usersEmail == '') {
|
|
|
|
|
$this->usersEmail = $email;
|
2015-12-19 20:23:57 -04:00
|
|
|
} else {
|
2016-02-29 12:45:35 -04:00
|
|
|
$emails = explode('|', $this->usersEmail);
|
2015-12-19 20:23:57 -04:00
|
|
|
if (array_search($email, $emails) === false) {
|
2016-02-29 12:45:35 -04:00
|
|
|
$this->usersEmail .= '|' . $email;
|
2015-12-19 20:23:57 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
2016-02-29 12:45:35 -04:00
|
|
|
* Get email of task users to app_uid
|
|
|
|
|
* @param $appUid id application
|
2015-12-19 20:23:57 -04:00
|
|
|
*
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
2016-02-29 12:45:35 -04:00
|
|
|
public function getEmailUsersTask($appUid)
|
2015-12-19 20:23:57 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2016-02-29 12:45:35 -04:00
|
|
|
$criteria = new Criteria('workflow');
|
|
|
|
|
$criteria->add(AppDelegationPeer::APP_UID, $appUid);
|
|
|
|
|
$criteria->add(AppDelegationPeer::DEL_THREAD_STATUS, 'OPEN');
|
2015-12-19 20:23:57 -04:00
|
|
|
|
2016-02-29 12:45:35 -04:00
|
|
|
$rsAppDelegation = AppDelegationPeer::doSelectRS($criteria);
|
|
|
|
|
$rsAppDelegation->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2015-12-19 20:23:57 -04:00
|
|
|
|
2016-02-29 12:45:35 -04:00
|
|
|
$group = new Groups();
|
|
|
|
|
$user = new Users();
|
|
|
|
|
$data = [];
|
|
|
|
|
while ($rsAppDelegation->next()) {
|
|
|
|
|
$row = $rsAppDelegation->getRow();
|
2016-03-15 17:36:41 -04:00
|
|
|
if (!empty($row['USR_UID'])) {
|
|
|
|
|
if ($user->userExists($row['USR_UID'])) {
|
|
|
|
|
$data = [];
|
|
|
|
|
$data[] = $user->load($row['USR_UID']);
|
|
|
|
|
} else {
|
|
|
|
|
$data = $group->getUsersOfGroup($row['USR_UID']);
|
|
|
|
|
}
|
2015-12-19 20:23:57 -04:00
|
|
|
|
2016-03-15 17:36:41 -04:00
|
|
|
foreach ($data as $dataUser) {
|
|
|
|
|
$this->addUserEmail($dataUser["USR_EMAIL"]);
|
|
|
|
|
}
|
2015-12-19 20:23:57 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $exception) {
|
|
|
|
|
error_log('Error: ' . $exception);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $appDocument
|
|
|
|
|
* @param string $typeDocument type document INPUT, OUTPUT_DOC, OUTPUT_PDF, ATTACHED
|
|
|
|
|
* @param string $mime MIME type of the file to insert.
|
|
|
|
|
* @param string $src location of the file to insert.
|
|
|
|
|
* @param string $name Title of the file to insert, including the extension.
|
|
|
|
|
* return string uid
|
|
|
|
|
*/
|
|
|
|
|
public function upload ($appDocument, $typeDocument, $mime, $src, $name)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$idFileDrive = null;
|
|
|
|
|
$this->existAppFolderDrive();
|
|
|
|
|
$appDoc = new AppDocument();
|
|
|
|
|
$result = $this->drive->uploadFile(
|
|
|
|
|
$mime,
|
|
|
|
|
$src,
|
|
|
|
|
$name,
|
|
|
|
|
$this->app->getAppDriveFolderUid()
|
|
|
|
|
);
|
|
|
|
|
if ($result->id !== null) {
|
|
|
|
|
$idFileDrive = $result->id;
|
|
|
|
|
$appDoc->setDriveDownload($typeDocument, $result->id);
|
|
|
|
|
$appDoc->update($appDocument);
|
|
|
|
|
}
|
|
|
|
|
return $idFileDrive;
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
error_log('Error upload file drive: ' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Download file drive
|
|
|
|
|
* @param $uidFileDrive
|
|
|
|
|
*/
|
|
|
|
|
public function download ($uidFileDrive)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
$result = $this->drive->downloadFile($uidFileDrive);
|
|
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
error_log('Error Download file drive: ' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $data
|
|
|
|
|
* @param string $typeDoc value INPUT, OUTPUT_DOC, OUTPUT_PDF, ATTACHED
|
|
|
|
|
*
|
|
|
|
|
* @return string url drive
|
|
|
|
|
*/
|
|
|
|
|
public function changeUrlDrive ($data, $typeDoc)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$urlDrive = $data['APP_DOC_DRIVE_DOWNLOAD'];
|
|
|
|
|
if ($this->getStatusDrive()) {
|
|
|
|
|
$driveDownload = @unserialize($data['APP_DOC_DRIVE_DOWNLOAD']);
|
|
|
|
|
$urlDrive = $driveDownload !== false
|
2016-02-29 12:45:35 -04:00
|
|
|
&& is_array($driveDownload)
|
|
|
|
|
&& array_key_exists($typeDoc, $driveDownload) ?
|
2015-12-19 20:23:57 -04:00
|
|
|
$driveDownload[$typeDoc] : $urlDrive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
error_log('Error change url drive: ' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $urlDrive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Synchronize documents drive
|
|
|
|
|
*
|
|
|
|
|
* @param boolean $log enable print cron
|
|
|
|
|
*/
|
|
|
|
|
public function synchronizeDrive ($log)
|
|
|
|
|
{
|
2015-12-20 11:28:29 -04:00
|
|
|
if (!$this->statusDrive) {
|
|
|
|
|
error_log("It has not enabled Feature Gmail");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-03-15 17:05:12 -04:00
|
|
|
$criteria = new Criteria('workflow');
|
2015-12-19 20:23:57 -04:00
|
|
|
$criteria->addSelectColumn(AppDocumentPeer::APP_DOC_UID);
|
|
|
|
|
$criteria->addSelectColumn(AppDocumentPeer::DOC_VERSION);
|
2015-12-21 13:24:20 -04:00
|
|
|
$criteria->add(
|
2016-03-15 17:05:12 -04:00
|
|
|
$criteria->getNewCriterion(AppDocumentPeer::SYNC_WITH_DRIVE, 'UNSYNCHRONIZED', Criteria::EQUAL)->
|
|
|
|
|
addOr($criteria->getNewCriterion(AppDocumentPeer::SYNC_PERMISSIONS, null, Criteria::NOT_EQUAL))
|
2015-12-21 13:24:20 -04:00
|
|
|
);
|
|
|
|
|
|
2016-03-15 17:05:12 -04:00
|
|
|
$criteria->addAscendingOrderByColumn('APP_DOC_CREATE_DATE');
|
|
|
|
|
$criteria->addAscendingOrderByColumn('APP_UID');
|
|
|
|
|
$rs = AppDocumentPeer::doSelectRS($criteria);
|
|
|
|
|
$rs->setFetchMode(ResultSet::FETCHMODE_ASSOC);
|
2015-12-19 20:23:57 -04:00
|
|
|
|
|
|
|
|
while ($rs->next()) {
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
$appDoc = new AppDocument();
|
|
|
|
|
$fields = $appDoc->load($row['APP_DOC_UID'], $row['DOC_VERSION']);
|
|
|
|
|
|
|
|
|
|
$appDocUid = $appDoc->getAppDocUid();
|
|
|
|
|
$docVersion = $appDoc->getDocVersion();
|
2016-03-15 17:05:12 -04:00
|
|
|
$filename = pathinfo($appDoc->getAppDocFilename());
|
|
|
|
|
$name = !empty($filename['basename']) ? $filename['basename'] : '';
|
|
|
|
|
$ext = !empty($filename['extension']) ? $filename['extension'] : '';
|
2015-12-19 20:23:57 -04:00
|
|
|
$appUid = G::getPathFromUID($appDoc->getAppUid());
|
2016-03-15 17:05:12 -04:00
|
|
|
$file = G::getPathFromFileUID($appDoc->getAppUid(), $appDocUid);
|
2015-12-19 20:23:57 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
$sw_file_exists_doc = false;
|
|
|
|
|
$sw_file_exists_pdf = false;
|
2016-03-15 17:05:12 -04:00
|
|
|
$sw_file_exists = false;
|
|
|
|
|
$realPath = '';
|
2016-03-11 19:05:40 -04:00
|
|
|
if ($appDoc->getAppDocType() === 'OUTPUT') {
|
2015-12-19 20:23:57 -04:00
|
|
|
$realPathDoc = PATH_DOCUMENT . $appUid . '/outdocs/' . $appDocUid . '_' . $docVersion . '.' . 'doc';
|
|
|
|
|
$realPathDoc1 = PATH_DOCUMENT . $appUid . '/outdocs/' . $name . '_' . $docVersion . '.' . 'doc';
|
|
|
|
|
$realPathDoc2 = PATH_DOCUMENT . $appUid . '/outdocs/' . $name . '.' . 'doc';
|
|
|
|
|
|
2016-03-15 17:05:12 -04:00
|
|
|
if (file_exists($realPathDoc)) {
|
2015-12-19 20:23:57 -04:00
|
|
|
$sw_file_exists = true;
|
|
|
|
|
$sw_file_exists_doc = true;
|
2016-03-15 17:05:12 -04:00
|
|
|
} elseif (file_exists($realPathDoc1)) {
|
2015-12-19 20:23:57 -04:00
|
|
|
$sw_file_exists = true;
|
|
|
|
|
$sw_file_exists_doc = true;
|
|
|
|
|
$realPathDoc = $realPathDoc1;
|
2016-03-15 17:05:12 -04:00
|
|
|
} elseif (file_exists($realPathDoc2)) {
|
2015-12-19 20:23:57 -04:00
|
|
|
$sw_file_exists = true;
|
|
|
|
|
$sw_file_exists_doc = true;
|
|
|
|
|
$realPathDoc = $realPathDoc2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$realPathPdf = PATH_DOCUMENT . $appUid . '/outdocs/' . $appDocUid . '_' . $docVersion . '.' . 'pdf';
|
2016-03-15 17:05:12 -04:00
|
|
|
$realPathPdf1 = PATH_DOCUMENT . $appUid . '/outdocs/' . $name . '_' . $docVersion . '.' . 'pdf';
|
2015-12-19 20:23:57 -04:00
|
|
|
$realPathPdf2 = PATH_DOCUMENT . $appUid . '/outdocs/' . $name . '.' . 'pdf';
|
|
|
|
|
|
2016-03-15 17:05:12 -04:00
|
|
|
if (file_exists($realPathPdf)) {
|
2015-12-19 20:23:57 -04:00
|
|
|
$sw_file_exists = true;
|
|
|
|
|
$sw_file_exists_pdf = true;
|
2016-03-15 17:05:12 -04:00
|
|
|
} elseif (file_exists($realPathPdf1)) {
|
2015-12-19 20:23:57 -04:00
|
|
|
$sw_file_exists = true;
|
|
|
|
|
$sw_file_exists_pdf = true;
|
|
|
|
|
$realPathPdf = $realPathPdf1;
|
2016-03-15 17:05:12 -04:00
|
|
|
} elseif (file_exists($realPathPdf2)) {
|
2015-12-19 20:23:57 -04:00
|
|
|
$sw_file_exists = true;
|
|
|
|
|
$sw_file_exists_pdf = true;
|
|
|
|
|
$realPathPdf = $realPathPdf2;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2016-03-15 17:05:12 -04:00
|
|
|
$realPath = PATH_DOCUMENT . $appUid . '/' . $file[0] . $file[1] . '_' . $docVersion . '.' . $ext;
|
2015-12-19 20:23:57 -04:00
|
|
|
$realPath1 = PATH_DOCUMENT . $appUid . '/' . $file[0] . $file[1] . '.' . $ext;
|
2016-03-15 17:05:12 -04:00
|
|
|
if (file_exists($realPath)) {
|
2015-12-19 20:23:57 -04:00
|
|
|
$sw_file_exists = true;
|
2016-03-15 17:05:12 -04:00
|
|
|
} elseif (file_exists($realPath1)) {
|
2015-12-19 20:23:57 -04:00
|
|
|
$sw_file_exists = true;
|
|
|
|
|
$realPath = $realPath1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($sw_file_exists) {
|
|
|
|
|
|
|
|
|
|
$this->loadApplication($appDoc->getAppUid());
|
2015-12-21 13:24:20 -04:00
|
|
|
$this->loadUser($fields['USR_UID']);
|
2015-12-19 20:23:57 -04:00
|
|
|
|
|
|
|
|
$emails = $appDoc->getSyncPermissions();
|
|
|
|
|
$emails = !empty($emails) ? explode('|', $emails) : array();
|
2015-12-20 09:11:02 -04:00
|
|
|
$result = null;
|
2015-12-19 20:23:57 -04:00
|
|
|
foreach ($emails as $index => $email) {
|
|
|
|
|
if (!empty($email)) {
|
2015-12-21 13:24:20 -04:00
|
|
|
|
2015-12-19 20:23:57 -04:00
|
|
|
if ($index == 0 && $fields['SYNC_WITH_DRIVE'] == 'UNSYNCHRONIZED') {
|
|
|
|
|
if ($log) {
|
2016-03-15 17:05:12 -04:00
|
|
|
eprintln('upload file:' . $name, 'green');
|
2015-12-19 20:23:57 -04:00
|
|
|
}
|
|
|
|
|
$this->drive->setDriveUser($email);
|
|
|
|
|
|
|
|
|
|
if ($appDoc->getAppDocType() == 'OUTPUT') {
|
|
|
|
|
|
|
|
|
|
if ($sw_file_exists_doc) {
|
2016-03-15 17:05:12 -04:00
|
|
|
$result = $this->upload($fields, 'OUTPUT_DOC', 'application/msword', $realPathDoc,
|
|
|
|
|
array_pop(explode('/', $realPathDoc)));
|
2015-12-19 20:23:57 -04:00
|
|
|
}
|
|
|
|
|
if ($sw_file_exists_pdf) {
|
2016-03-15 17:05:12 -04:00
|
|
|
$info = finfo_open(FILEINFO_MIME_TYPE);
|
|
|
|
|
$result = $this->upload($fields, 'OUTPUT_PDF', finfo_file($info, $realPathPdf),
|
|
|
|
|
$realPathPdf, array_pop(explode('/', $realPathPdf)));
|
2015-12-19 20:23:57 -04:00
|
|
|
}
|
2016-03-15 17:05:12 -04:00
|
|
|
} else {
|
|
|
|
|
$info = finfo_open(FILEINFO_MIME_TYPE);
|
|
|
|
|
$mime = finfo_file($info, $realPath);
|
|
|
|
|
$type = $appDoc->getAppDocType();
|
|
|
|
|
$result = $this->upload($fields, $type, $mime, $realPath, $name);
|
2015-12-19 20:23:57 -04:00
|
|
|
}
|
2016-03-15 17:05:12 -04:00
|
|
|
|
2015-12-19 20:23:57 -04:00
|
|
|
} else {
|
2015-12-21 13:24:20 -04:00
|
|
|
$this->drive->setDriveUser($this->user->getUsrEmail());
|
|
|
|
|
}
|
|
|
|
|
if ($log) {
|
2016-03-15 17:05:12 -04:00
|
|
|
eprintln('Set Permission:' . $email, 'green');
|
2015-12-19 20:23:57 -04:00
|
|
|
}
|
2015-12-21 13:24:20 -04:00
|
|
|
$this->drive->setPermission($this->app->getAppDriveFolderUid(), $email, 'user', 'writer');
|
2015-12-19 20:23:57 -04:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-20 09:11:02 -04:00
|
|
|
if ($result != null) {
|
|
|
|
|
$fields['SYNC_WITH_DRIVE'] = 'SYNCHRONIZED';
|
|
|
|
|
$fields['SYNC_PERMISSIONS'] = null;
|
|
|
|
|
}
|
2015-12-19 20:23:57 -04:00
|
|
|
} else {
|
|
|
|
|
$fields['SYNC_WITH_DRIVE'] = 'NO_EXIST_FILE_PM';
|
|
|
|
|
if ($log) {
|
2016-03-15 17:05:12 -04:00
|
|
|
eprintln('File no exists:' . $name, 'red');
|
2015-12-19 20:23:57 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$appDoc->update($fields);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-28 11:53:07 -04:00
|
|
|
/**
|
|
|
|
|
* Add users to documents drive to give permissions
|
|
|
|
|
*
|
|
|
|
|
* @param $appUid Id application
|
|
|
|
|
* @param $emails array with emails which can be null
|
|
|
|
|
*
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
public function addUsersDocumentDrive ($appUid, $emails=null)
|
2015-12-19 20:23:57 -04:00
|
|
|
{
|
2016-03-28 11:53:07 -04:00
|
|
|
if (is_array($emails)) {
|
|
|
|
|
foreach ($emails as $index => $email) {
|
|
|
|
|
$this->addUserEmail($email);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->getEmailUsersTask($appUid);
|
|
|
|
|
}
|
2015-12-19 20:23:57 -04:00
|
|
|
|
|
|
|
|
$criteria = new Criteria( 'workflow' );
|
|
|
|
|
$criteria->add( AppDocumentPeer::APP_UID, $appUid );
|
|
|
|
|
$criteria->addAscendingOrderByColumn( 'DOC_VERSION' );
|
|
|
|
|
$rs = AppDocumentPeer::doSelectRS( $criteria );
|
|
|
|
|
$rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
|
|
|
|
|
|
|
|
|
$appDoc = new AppDocument();
|
|
|
|
|
while ($rs->next()) {
|
|
|
|
|
$row = $rs->getRow();
|
2016-02-29 12:45:35 -04:00
|
|
|
if (empty($row['SYNC_PERMISSIONS'])) {
|
|
|
|
|
$row['SYNC_PERMISSIONS'] = $this->usersEmail;
|
|
|
|
|
} else {
|
|
|
|
|
$emails = explode('|', $row['SYNC_PERMISSIONS']);
|
|
|
|
|
foreach ($emails as $email) {
|
|
|
|
|
$this->addUserEmail($email);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-19 20:23:57 -04:00
|
|
|
$appDoc->update($row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|