'Process has been unblocked', App_FormBuilder_View::MSG_CANT_UNBLOCK => 'Process can not be unblocked', App_FormBuilder_View::MSG_CANT_EDIT => 'Process can not be edited, cause it is blocked', App_FormBuilder_View::MSG_SAVED => 'Process has been saved', App_FormBuilder_View::MSG_SUBMISSION_SAVED => 'Data have been saved', App_Process_Media_View::MSG_ANNOTATION_CANT_EDIT => 'Annotation can not be edited', App_Process_Media_View::MSG_ANNOTATION_UPDATED => 'Annotation has been updated', App_Process_Media_View::MSG_ANNOTATION_ERROR => 'Can not create Annotation', ); protected $_actions = array('list', 'new', 'insert', 'edit', 'update', 'delete', 'cancel', 'save', 'unblock', 'savePositions', 'deleteElement', 'view', 'popup', 'loadItem', 'submit', 'viewResults', 'print', 'removeSet', 'annotation', 'saveAnnotation'); protected $_templatePath = array('Process', 'FormBuilder', 'ViewController'); protected $_departmentId; protected $_popupUrl; protected $_currentMedia; protected $_setId; protected $_annotationBgFile = null; protected static $_pdfPageHeaderPattern = '{partNumber} | Rev. {revision} | {partClient} > {partNumber} - {partName}{headerSuffix}'; protected static $_pdfPageFooterPattern = 'This printed copy expires at {time} on {date}'; protected function _initAction() { if ($this->getConfig('type') == 'print') { $this->_defaultAction = 'print'; } else { $params = $this->getRestParams(); if (count($params) == 1 && ctype_digit($params[0])) { $this->_defaultAction = 'loadItem'; } } if ($this->dataObj->getPrimaryKey()) { $this->doc->setTitle($this->doc->getTitle() . ' :: ' . $this->dataObj->getData('name')); } $this->_actions = array('list', 'viewResults', 'popup', 'loadItem', 'print', 'cancel', 'createStamp', 'addMark', 'updateMark', 'annotation', 'saveAnnotation'); if (App_User_Auth::getInstance()->hasIdentity()) { if ($this->doc->acl->isAllowed(App_User_Auth::getInstance()->getData('id'), 'process', 'add')) { $this->_actions = array_merge($this->_actions, array('new', 'insert', 'edit', 'update', 'delete', 'save', 'unblock', 'annotation', 'saveAnnotation')); } if ($this->_getDepartmentAccess()) { $this->_actions = array_merge($this->_actions, array('savePositions', 'deleteElement', 'view', 'submit', 'removeSet')); } } parent::_initAction(); $departmentId = (int) Qs_Sys_Request::getGetValue('departmentId'); if (!empty($departmentId) && ctype_digit($departmentId)) { $this->_departmentId = $departmentId; } return $this; } protected function _getDepartmentAccess() { $departmentId = $this->dataObj->getData('departmentId'); if (!$departmentId) { $departmentId = (int) Qs_Request::getGetValue('departmentId'); } if (!$departmentId && in_array(Qs_Request::getGetValue('action'), array('savePositions', 'deleteElement'))) { $departmentId = $this->dataObj->getDepartmentIdByFormElementId(); } if (!$departmentId) { $this->_actions = array('list', 'viewResults', 'popup', 'loadItem', 'print', 'cancel', 'createStamp', 'addMark', 'updateMark', 'annotation', 'saveAnnotation'); } $department = $this->dataObj->tableDepartment->search($departmentId); $departmentId = $department['parentId'] ? $department['parentId'] : $departmentId; return ($departmentId && $this->doc->acl->isAllowed($this->doc->getAuthData('id'), App_Acl_Obj::DEPARTMENT_PREFIX . $departmentId, App_Acl_Obj::DEPARTMENT_PRIVILEGE)); } protected function _bindFormFields(Qs_Form $form) { $form->addElement( 'select', 'departmentId', array( 'label' => 'Choose the appropriate Department/Sub-Department', 'required' => true, 'multiOptions' => $this->dataObj->getDepartmentTree(), 'value' => $this->_departmentId, 'escapeLabel' => false ) ); $form->addElement('text', 'name', array('label' => 'Process Name', 'required' => true)); $form->addElement( 'checkbox', 'isMedia', array( 'label' => 'Image/Video Process', 'decoration' => 'simple', 'checkedValue' => 'y', 'uncheckedValue' => 'n' ) ); $form->addElement( 'checkbox', 'isMultiply', array( 'label' => 'Multiply Process', 'decoration' => 'simple', 'checkedValue' => 'y', 'uncheckedValue' => 'n' ) ); $form->addElement( 'checkbox', 'nonExport', array( 'label' => 'Non Export Process', 'decoration' => 'simple', 'checkedValue' => 'y', 'uncheckedValue' => 'n' ) ); $form->addElement( 'checkbox', 'singlePagePrint', array( 'label' => 'Single Page Print Process', 'decoration' => 'simple', 'checkedValue' => 'y', 'uncheckedValue' => 'n' ) ); $form->addElement( 'checkbox', 'nonUpdateable', array( 'label' => 'Non-updateable', 'decoration' => 'simple', 'checkedValue' => 'y', 'uncheckedValue' => 'n' ) ); $form->addElement( 'extendedImage', 'sidebar', array( 'label' => 'Sidebar Image', 'resize' => array( 'width' => self::SIDEBAR_WIDTH, 'height' => self::SIDEBAR_HEIGHT, 'method' => 'inner', 'quality' => 94, ), ) ); parent::_bindFormFields($form); return $this; } protected function _doDelete() { if ($this->dataObj->getPartCountByKey()) { $this->_setBackError(App_Process_View::NOT_ALLOWED_DELETE); $this->_doBack(); } parent::_doDelete(); } protected function _doView($messages = array()) { $this->doc->setHeader(''); $this->dataObj->setLastProcess($this->doc->getAuthData('id')); $partId = Qs_Request::getRequestValue('partId'); $partObj = new App_Part_Obj(array('primaryKey' => $partId)); if ($partId && ctype_digit($partId) && $partObj->getData()) { if ($this->dataObj->getData('isMedia') == 'y') { $mediaUrl = Qs_SiteMap::find(null, array('type' => 'Process_Media_'), array('type' => 'default'), 'url'); Qs_Http::redirect($mediaUrl . '/' . $this->dataObj->getPrimaryKey() . '/' . $partId); return $this; } else { $this->_saveBackUrl(); if ($this->dataObj->getData('isMultiply') == 'y') { $this->_setId = $this->_getSetId(); } $item = $this->_getViewItem(); if ($this->dataObj->getData('isMultiply') == 'y') { $item['currentSet'] = $this->_getSetId(); $item['setIds'] = $this->dataObj->getSetIds($partId); $item['currentSetTitle'] = $item['setIds'][$item['currentSet']]; $item['newSetId'] = max(array_keys($this->dataObj->getSetIds($partId, 'setId', null, true))) + 1; if ($this->_setId == $item['newSetId'] || $this->_setId === null) { // adding new set $newSet = true; $item['newSetTitle'] = max($item['setIds']) + 1; } else { $newSet = false; } $this->doc->addInitFunction('App_Part.init', array(array('newSetCurrent' => $newSet))); $params = Qs_Array::excludeKey(Qs_Request::getGet(), 'setId'); $item['setAlias'] = http_build_query($params, null, '&'); $item['removeSetAlias'] = http_build_query(Qs_Array::excludeKey($params, 'action'), null, '&'); } $item['form']->setDefaults(array('comments' => $partObj->getData('comments'), 'versionType' => App_Part_Obj::REVISION_LOCKED)); $item['messages'] = $messages; $this->_addItem($item); } } else { $this->doc->display404(); } return $this; } protected function _doRemoveSet() { $getArray = Qs_Request::getGet(); $getArray['action'] = 'view'; unset($getArray['setId']); $this->_setBackUrl(BASE_URL_LANGUAGE . '/' . CURRENT_PAGE . '?' . http_build_query($getArray)); $partId = (int) Qs_Request::getGetValue('partId'); $setId = (int) Qs_Request::getGetValue('setId'); $this->dataObj->removeSet($partId, $setId); $this->_doBack(); return $this; } protected function _getPopupAlias() { return Qs_SiteMap::find( null, array('type' => 'Process_'), array('type' => 'popup'), 'fullAlias' ); } protected function _getStampAlias() { return Qs_SiteMap::find( null, array('type' => 'Process_Media_'), array('type' => 'stamp'), 'fullAlias' ); } protected function _doPopup() { $params = $this->getRestParams(); list($processId, $partId, $mediaId) = $params; $revisionId = Qs_Request::getRequestValue('revisionId'); if (count($params) == 3 && ctype_digit($processId) && ctype_digit($partId) && ctype_digit($mediaId)) { $item = array(); $mediaList = $this->dataObj->getMediaList($processId, $partId, $revisionId); $this->assignAnnotations($mediaList, $revisionId); $item['list'] = $mediaList; $item['popupUrl'] = BASE_URL . '/' . $this->_getPopupAlias(); $this->_currentMedia = $this->dataObj->getMediaById($mediaId); $currentMedia = array($this->_currentMedia); $this->assignAnnotations($currentMedia, $revisionId); $item['currentMedia'] = reset($currentMedia); $item['revisionId'] = $revisionId; $item['tpl'] = $this->getTemplate('mediaPopup.tpl'); $this->doc->addItem($item); } return $this; } protected function _doPopupAjax() { $this->_doPopup(); $this->_displayJson(array('content' => $this->doc->fetch(), 'type' => $this->_currentMedia['type'], 'mediaId' => $this->_currentMedia['id'], 'params' => $this->_getFlashVideoParams())); } protected function _doAnnotation($form = null) { $srcHash = Qs_Request::getRequestValue('srcId'); $partId = Qs_Request::getRequestValue('partId'); $processId = Qs_Request::getRequestValue('processId'); if ($partId && ctype_digit($partId) && $processId && ctype_digit($processId)) { $mediaObj = new App_Process_Media_Obj(); $part = $mediaObj->getPartById($partId); $this->dataObj->setPrimaryKey($processId); $processName = $this->dataObj->getData('name'); $this->doc->setHeader($processName . ' >> ' . $part['number'] . ' - ' . $part['name']); $partObj = new App_Part_Obj(array('primaryKey' => $partId)); $partData = $partObj->getData(); } $this->_annotationBgFile = base64_decode($srcHash); if ($srcHash && $this->_annotationBgFile && file_exists(WWW_PATH . '/' . Qs_ImageFs::WEB_PATH . '/' . $this->_annotationBgFile) ){ $form = $this->getAnnotationForm(); $comments = (isset($partData['comments']) && isset($partData['revisionStatus']) && ($partData['revisionStatus'] == App_Part_Obj::REVISION_LOCKED_BY_YOU)) ? $partData['comments'] : null; $form->setDefaults(array( 'svgAnnotation' => $this->_annotationBgFile, 'versionType' => App_Part_Obj::REVISION_LOCKED, 'comments' => $comments )); parent::_renderMainForm($form); } else { $this->_setBackError($this->_messages[App_Process_Media_View::MSG_ANNOTATION_CANT_EDIT]); $this->_doBack(); } return $this; } /** * @return Qs_Form */ public function getAnnotationForm() { $form = $this->_getBaseForm(); $this->_bindAnnotationFormFields($form); $this->_bindFormButtons($form); $form->addElement('hidden', 'action', array('value' => 'saveAnnotation')); $form->addElement('hidden', 'id', array('value' => $this->dataObj->getPrimaryKey())); return $form; } protected function _bindAnnotationFormFields(Qs_Form $form) { $partId = Qs_Request::getRequestValue('partId'); $form->addElement('hidden', 'partId', array('value' => $partId)); if ($this->dataObj->getData('isMultiply') == 'y') { $form->addElement('hidden', 'setId', array('value' => $this->_getSetId())); } $partObj = new App_Part_Obj(array('primaryKey' => $partId)); $partData = $partObj->getData(); $revisionId = ($partData['revisionStatus'] == App_Part_Obj::REVISION_LOCKED_BY_YOU) ? $partData['blockedVersion'] : $partData['currentVersion']; $currentRevision = App_Process_Media_Obj::getLastAnnotationRevision($this->_annotationBgFile, $revisionId); $form->addElement( 'svgEditor', 'svgAnnotation', array( 'required' => false, 'label' => 'Annotation', 'revision' => $currentRevision ) ); $this->doc->addScript('js/app/part.js'); $this->doc->addInitFunction('App_Part_Administration.init', array(array('formSelector' => '#process-form'))); App_Part_View::appendAdministrativeOptions($form, $this->_doc, $partData['revisionStatus'], $partData['blockedUser'], false); return $this; } protected function _doSaveAnnotationAjax() { $form = $this->getAnnotationForm(); $this->_validateAjax($form); } protected function _doSaveAnnotation() { $form = $this->getAnnotationForm(); $data = $this->_getData(); if ($form->validate() && App_Process_Media_View::validateAnnotation($data['svgAnnotation'])) { $elements = $this->dataObj->getPart2ProcessData($data['partId'], $this->_getSetId()); foreach ($elements as $element) { $data[$element['name']] = $element['value']; } $this->dataObj->initFromForm($data); $submissionId = $this->dataObj->saveSubmission( $data['partId'], $data['versionType'], $data['comments'], $this->_getSetId() ); if ($submissionId && App_Process_Media_View::saveSvgFile($data['svgAnnotation'], $this->dataObj->getAnnotationRevision()) ) { $this->_postUpdate(); $this->_setBackMessage($this->_messages[App_Process_Media_View::MSG_ANNOTATION_UPDATED]); } else { $this->_setBackMessage($this->_messages[App_Process_Media_View::MSG_ANNOTATION_ERROR]); } $this->_doBack(); } else { $this->_doBack(); } return $this; } protected function _doLoadItem() { $params = $this->getRestParams(); $mediaId = (int) $params[0]; $revisionId = (int) Qs_Request::getRequestValue('revisionId'); if (count($params) == 1 && ctype_digit($params[0])) { $item = array(); $this->_currentMedia = $this->dataObj->getMediaById($mediaId); $currentMedia = array($this->_currentMedia); $this->assignAnnotations($currentMedia, $revisionId); $item['currentMedia'] = reset($currentMedia); $item['tpl'] = $this->getTemplate('mediaPopupContent.tpl'); $this->doc->addItem($item); } return $this; } protected function _getViewForm() { $form = parent::_getViewForm(); $partId = Qs_Request::getRequestValue('partId'); $form->addElement('hidden', 'partId', array('value' => $partId)); if ($this->dataObj->getData('isMultiply') == 'y') { $form->addElement('hidden', 'setId', array('value' => $this->_getSetId())); } $partObj = new App_Part_Obj(array('primaryKey' => $partId)); $this->doc->addScript('js/app/part.js'); $this->doc->addInitFunction('App_Part_Administration.init', array(array('formSelector' => '#process-form'))); App_Part_View::appendAdministrativeOptions($form, $this->_doc, $partObj->getData('revisionStatus'), $partObj->getData('blockedUser'), $this->_action == 'submit'); $form->addFormRule(array($this, 'validateForm')); return $form; } protected function _getFormObject() { $form = parent::_getFormObject(); $form->addFormRule(array($this, 'validateForm')); return $form; } public function validateForm($data) { $partId = Qs_Request::getRequestValue('partId'); $partObj = new App_Part_Obj(array('primaryKey' => $partId)); $errors = App_Part_View::validateRevision($partObj->getData(), $data); return (empty($errors)) ? true : $errors; } protected function _getFlashVideoParams($force = false, $videoFile = null) { if (is_null($videoFile)) { $videoFile = $this->_currentMedia['video']; } if ($this->_currentMedia['type'] != 'video' && !$force) { return array(); } return array( 'swfUrlStr' => BASE_URL . '/flash/player.swf', 'replaceElemIdStr' => self::CONTAINER_ID, 'widthStr' => self::VIDEO_WIDTH, 'heightStr' => self::VIDEO_HEIGHT, 'swfVersionStr' => self::FLASH_VERSION, 'xiSwfUrlStr' => '', 'flashvarsObj' => array( 'autostart' => false, 'file' => rawurlencode(BASE_URL . '/userfiles/files/' . $videoFile) ), 'parObj' => array( 'wmode' => 'transparent', 'quality' => 'high', 'allowfullscreen' => true, 'allowscriptaccess' => 'always' ), 'attObj' => array() ); } protected function _doLoadItemAjax() { $this->_doLoadItem(); $this->_displayJson(array('content' => $this->doc->fetch(), 'type' => $this->_currentMedia['type'], 'mediaId' => $this->_currentMedia['id'], 'params' => $this->_getFlashVideoParams())); } protected function _getViewItem() { $item = parent::_getViewItem(); if ($item['nonUpdateable'] == 'y') { $queryParams = $_GET; $queryParams['action'] = 'viewResults'; Qs_Http::redirect(Qs_Request::getBaseUrl() . '?' .http_build_query($queryParams)); } $item['partElements'] = $this->_getElementsItems('view', true); if (null !== ($partId = Qs_Request::getRequestValue('partId'))) { $part = $this->dataObj->tablePart->search($partId); $item['partFormHeight'] = $part['height']; } $partId = Qs_Request::getRequestValue('partId'); $this->_addItemInformation($partId, $item); return $item; } /** * @param string $action * @param bool $part * @return array */ protected function _getElementsItems($action = 'view', $part = null) { if (null !== ($partId = Qs_Request::getRequestValue('partId')) && null !== ($elements = $part ? $this->dataObj->getPartGeneralData($partId, $this->_getSetId()) : $this->dataObj->getPart2ProcessData($partId, $this->_getSetId()))) { $defaultData = array(); foreach ($elements as $element) { $defaultData[$element['name']] = $element['value']; } } else { $defaultData = null; } $elements = $part ? $this->_getPartElementsItems($action, $defaultData) : parent::_getElementsItems($action, $defaultData); return $elements; } protected function _getPartElementsItems($action = 'view', $defaultData = null) { /** * @var App_FormBuilder_Element_AbstractView $elementView */ $elements = array(); $elementList = $this->dataObj->getElementList($action != 'view', true, Qs_Request::getRequestValue('partId')); foreach ($elementList as $element) { $class = 'App_FormBuilder_Element_' . App_FormBuilder_Element_Obj::$types[$element['typeId']] . '_View'; $elementView = new $class(array('doc' => $this->doc)); $elementView->dataObj->setPrimaryKey($element['id']); $element = $elementView->getItem($action) + $element; $noDefaultElements = array( App_FormBuilder_Element_Obj::STATIC_TEXT_ID, App_FormBuilder_Element_Obj::IMAGE_ID, App_FormBuilder_Element_Obj::MULTI_CHECKBOX_ID, App_FormBuilder_Element_Obj::MULTI_TEXT_ID ); if (null !== $defaultData && $element['typeId'] != App_FormBuilder_Element_Obj::STATIC_TEXT_ID && isset($defaultData[$element['name']])) { $element['defaultValue'] = $defaultData[$element['name']]; } elseif ($action == 'view' && !in_array($element['typeId'], $noDefaultElements)) { $element['defaultValue'] = Qs_Request::getRequestValue($element['name'], $element['defaultValue']); } $element['name'] = $element['formType'] . $element['name']; $elements[] = new Qs_Doc_Item($element); } return $elements; } protected function _saveSubmission() { $this->dataObj->saveSubmission(Qs_Request::getRequestValue('partId'), Qs_Request::getRequestValue('versionType'), Qs_Request::getRequestValue('comments'), $this->_getSetId()); if (Qs_Request::getRequestValue('versionType') == App_Part_Obj::REVISION_APPROVED) { $backUrl = Qs_Request::getBaseUrl() . '?' . http_build_query(array( 'action' => 'viewResults', 'id' => $this->dataObj->getPrimaryKey(), 'partId' => Qs_Request::getRequestValue('partId') )); $this->_setBackUrl($backUrl ); } return $this; } public function fillConfigForm(Qs_Form $form) { $form->addElement( 'select', 'type', array( 'label' => 'Block Type', 'multiOptions' => array( 'default' => 'Default', 'popup' => 'Popup', 'print' => 'Print', ) ) ); return $this; } protected function _doViewResults() { $this->doc->addStylesheet('css/jquery.fancybox-1.3.4.css'); $this->doc->addScript('js/jquery.fancybox-1.3.4.js'); $this->doc->setHeader(''); $this->doc->addScript('js/app/process-part.js'); $this->doc->addInitFunction('App_Process_Part.init', array()); $this->dataObj->setLastProcess($this->doc->getAuthData('id')); $partId = Qs_Request::getRequestValue('partId'); $revisionId = Qs_Request::getRequestValue('revisionId'); if (!$revisionId) { $partObj = new App_Part_Obj(array('primaryKey' => $partId)); $partRevisionData = $partObj->getData('revision'); $revisionId = $partRevisionData['id']; } if (Qs_Request::getGetValue('partId') && ctype_digit(Qs_Request::getGetValue('partId'))) { $item = $this->_getViewResultsItem($partId, $revisionId); $urlParams = array( 'action' => 'view', 'id' => $this->dataObj->getPrimaryKey(), 'partId' => $partId ); $departmentAccess = $this->_getDepartmentAccess(); $item['editLink'] = $departmentAccess && $item['nonUpdateable'] != 'y'? (BASE_URL . '/' . CURRENT_PAGE . '?' . http_build_query($urlParams)) : ''; if ($this->dataObj->getData('isMedia') == 'y') { $item['reportStampLink'] = App_Process_Media_View::getReportStampPageUrl(); $mediaList = $this->dataObj->getMediaList($this->dataObj->getPrimaryKey(), $partId, $revisionId); $this->assignStamps($mediaList); $this->assignAnnotations($mediaList, $revisionId); $item['list'] = $mediaList; $item['popupAlias'] = $this->_getPopupAlias(); $item['stampAlias'] = $departmentAccess ? $this->_getStampAlias() : ''; $this->_addItem($item); $this->_setBackUrl(Qs_Request::getFinalBaseUrl() . Qs_Request::getUrl(), $item['stampAlias']); $this->doc->addScript('js/jquery.bxSlider.min.js'); $this->doc->addStyleSheet('css/bx-slider/bx.css'); $this->doc->addScript('js/app/media.js'); $this->doc->addInitFunction('App_Media.init', array()); $this->doc->addScript('js/swfobject.js'); } else { if ($this->dataObj->getData('isMultiply') == 'y') { $item['setId'] = $item['currentSet'] = $this->_getSetId(); $item['setIds'] = $this->dataObj->getSetIds($partId, 'setId', $revisionId); $item['currentSetTitle'] = $item['setIds'][$item['currentSet']]; $params = Qs_Array::excludeKey(Qs_Request::getGet(), 'setId'); $item['setAlias'] = http_build_query($params, null, '&'); } $this->_doc->addStylesheet('css/formBuilder.css'); //vdie($item); $this->_addItem($item); } } else { $this->doc->display404(); } return $this; } public function assignStamps(&$list) { App_Process_Media_Obj::assignStamps($list); return $this; } public function assignAnnotations(&$list, $revisionId = null) { $mediaObj = new App_Process_Media_Obj(); $mediaObj->assignAnnotation($list, $revisionId); return $this; } public static function getAnnotationSvg($data, $revisionId = null) { $result = null; if(is_object($data)) { $data = (array) $data; $data['value'] = ($data['defaultValue']) ? $data['defaultValue'] : null; } if (isset($data['typeId']) && $data['typeId'] == App_FormBuilder_Element_Obj::IMAGE_ID && $data['value']) { $revision = App_Process_Media_Obj::getLastAnnotationRevision($data['value'], $revisionId); $revisionSuffix = (!empty($revision)) ? '_rev_' . $revision : ''; $svg_filename = pathinfo($data['value'], PATHINFO_FILENAME) . $revisionSuffix . '.svg'; if (file_exists(WWW_PATH . '/' . Qs_ImageFs::WEB_PATH . '/' . $svg_filename)) { $result = $svg_filename; } } return $result; } protected function _getViewResultsItem($partId, $revisionId) { $item = $this->dataObj->getData(); $item['tpl'] = $this->getTemplate('viewResults.tpl'); $item['revisionId'] = $revisionId; $item['elements'] = $this->_getResultElements($partId, false, $revisionId); $item['partElements'] = $this->_getResultElements($partId, false, $revisionId, true); if (null !== ($partId = Qs_Request::getRequestValue('partId'))) { $part = $this->dataObj->tablePart->search($partId); $item['partFormHeight'] = $part['height']; } $this->_addItemInformation($partId, $item, $revisionId); return $item; } protected function _getResultElements($partId, $print = false, $revisionId, $partElement = false, $setId = null) { $setId = (null === $setId) ? $this->_getSetId() : $setId; /** * @var App_FormBuilder_Element_AbstractView $elementView */ $elements = $partElement ? $this->dataObj->getPartGeneralData($partId, $setId, $revisionId) : $this->dataObj->getPart2ProcessData($partId, $setId, $revisionId); if (null !== $elements) { $elements = $this->_prepareElementList($elements, $print, $revisionId); } return $elements; } protected function _prepareElementList($elements, $print, $revisionId) { $resultElements = array(); foreach ($elements as $elementKey => $element) { $class = 'App_FormBuilder_Element_' . App_FormBuilder_Element_Obj::$types[$element['typeId']] . '_View'; /** @var App_FormBuilder_Element_AbstractView $elementView */ $elementView = new $class(array('doc' => $this->doc)); $elementView->dataObj->setPrimaryKey($element['id']); $element = $elementView->getItem('viewResults') + $element; if ($element['formType'] == App_FormBuilder_Obj::FORM_TYPE_PART) { $element['name'] = App_FormBuilder_Obj::FORM_TYPE_PART . $element['name']; }; if ($element['typeId'] == App_FormBuilder_Element_Obj::IMAGE_ID) { if (pathinfo($element['value'], PATHINFO_EXTENSION) == self::VIDEO_EXTENSION && !$print) { $element['type'] = 'video'; $videoParams = $this->_getFlashVideoParams(true, $element['value']); $videoParams['heightStr'] = $element['height']; $videoParams['widthStr'] = $element['width']; $this->doc->addScript('js/swfobject.js'); $this->doc->addScript('js/app/media.js'); $this->doc->addInitFunction('App_Media.displayVideo', array($videoParams)); } else { $element['type'] = 'image'; $element['annotation'] = $this->getAnnotationSvg($element, $revisionId); } } $resultElements[$elementKey] = new Qs_Doc_Item($element); } return $resultElements; } protected function _addItemInformation($partId, &$item, $revisionId = null, $print = false) { $partObject = new App_Part_Obj(array('primaryKey' => $partId, 'revisionId' => $revisionId)); $item['partInfo'] = $partObject->getData(); $clientObject = new App_Client_Obj(array('primaryKey' => $item['partInfo']['clientId'])); $item['partInfo']['client'] = $clientObject->getData('name'); $item['currentProcess'] = $this->dataObj->getPrimaryKey(); $item['currentProcessTitle'] = $this->dataObj->getData('name'); $item['currentDepartment'] = $this->dataObj->getData('parentDepartmentId'); if (!$print) { $departmentObject = new App_Department_Obj(); $item['partInfo']['processes'] = $departmentObject->getPartProcessList($partId, null, $partObject->getRevisionId()); $item['url'] = Qs_Sys_SiteMap::findFirst(null, array('type' => 'Process_'), array('type' => 'default'), 'url'); $item['partUrl'] = Qs_Sys_SiteMap::findFirst(null, array('type' => 'Part_'), null, 'url'); $item['printUrl'] = Qs_Sys_SiteMap::findFirst(null, array('type' => 'Process_'), array('type' => 'print'), 'url'); } $item['clientUrl'] = Qs_Sys_SiteMap::findFirst(null, array('type' => 'Client_'), null, 'url'); $item['isAuthorized'] = App_User_Auth::getInstance()->isLoggedIn(); return $this; } protected function _initFromForm(Qs_Form $form) { $data = $form->getValues(); if ($data['action'] == 'save') { $data['new'] = 'n'; } $this->dataObj->initFromForm($data); return $this; } protected function _doEdit($form = null) { $this->doc->addScript('js/app/process.js'); $this->doc->addInitFunction('App_Process.init', array()); return parent::_doEdit($form); } protected function _doList() { $departmentPage = Qs_Sys_SiteMap::findFirst(null, array('type' => 'Department_'), array('type' => 'default')); $this->_setBackUrl($departmentPage['fullAlias']); $session = new Qs_Session_Namespace(Qs_Constant::get('CURRENT_PAGE')); if (isset($session->message)) { $this->_setBackMessage($session->message); } $this->_doBack(); } /** * Save PDF Export file to separate folder * * @param string $sourceFile * @param int $partId * @param null|int $departmentId * @param null|int $processId * @param null|int $setId * @return bool * @throws Exception */ protected function _doSavePdfExportFile($sourceFile, $partId, $departmentId = null, $processId = null, $setId = null) { /* /.pdf */ $pdfName = App_Part_ExportObj::getPartNumber($partId); $destinationPath = $this->_getBaseExportPath('pathPdfExportPart'); if ($processId || '0' === $processId) { if ($processId) { /* //,,.pdf */ $this->dataObj->setPrimaryKey($processId); $processName = $this->_prepareFsName($this->dataObj->getData('name')); $departmentId = $departmentId ?: (int) $this->dataObj->initData()->getData('departmentId'); $departmentObject = new App_Department_Obj(array('primaryKey' => $departmentId)); $departmentName = $this->_prepareFsName($departmentObject->getData('name')); $pdfName .= ',' . $departmentName; $pdfName .= ',' . $processName; $destinationPath = $this->_getBaseExportPath('pathPdfExportProcess'); $destinationPath .= '/' . $departmentName; if ($setId) { /* //,,,.pdf */ $destinationPath = $this->_getBaseExportPath('pathPdfExportSet'); $destinationPath .= '/' . $departmentName; $pdfName .= ',' . $setId; } } else { // processId: 0 $destinationPath = $this->_getBaseExportPath('pathPdfExportProcess'); $pdfName .= ',general_specifications'; } } else { if ($departmentId) { /* /,.pdf */ $destinationPath = $this->_getBaseExportPath('pathPdfExportDepartment'); $departmentObject = new App_Department_Obj(array('primaryKey' => $departmentId)); $departmentName = $this->_prepareFsName($departmentObject->getData('name')); $pdfName .= ',' . $departmentName; } } $pdfName .= '.pdf'; $this->_prepareExportPath($destinationPath); $exportFilePath = $destinationPath . '/' . $pdfName; file_exists($exportFilePath) && @chmod($exportFilePath, 0644); if (copy($sourceFile, $exportFilePath)) { chmod($exportFilePath, 0644); $this->_saveExportInfo($partId, $pdfName); return true; } else { throw App_Part_Export_NotMovedException::create($sourceFile, $exportFilePath); } } protected function _getBaseExportPath($settingName) { $path = App_Settings_Obj::get($settingName); $path = $path ? $path : constant('WWW_PATH') . '/' . App_Part_ExportObj::PART_EXPORT_DIR; return Qs_Fs::normalize($path); } /** * Validate export directory, and try to create if it doesn't exist * @param string $path * @return object $this * @throws Exception */ protected function _prepareExportPath($path) { $validator = new Qs_Validate_ExportDir(); if (!$validator->isValid($path)) { $msg = 'Error: ' . implode(";\n", $validator->getMessages()); throw new Exception($msg); } if (!Qs_ImageFs::ensureDir($path)) { $msg = 'Can not create part export dir: ' . $path; throw new Exception($msg); } return $this; } protected function _prepareFsName($name) { return str_replace(' ', '-', strtolower(Qs_Fs::filterName($name))); } protected function _saveExportInfo($partId, $pdfFile) { if ($partId && $pdfFile && $authData = App_User_Auth::getInstance()->getData()) { $partObject = new App_Part_Obj(array('primaryKey' => $partId)); $data = array( 'exportDate' => date('Y-m-d H:i:s'), 'revision' => Qs_Array::group($partObject->getData('revisions'), array('type'))['current']['version'], 'exportedBy' => $authData['firstName'] . ' ' . $authData['lastName'], 'pdfFile' => $pdfFile ); $this->dataObj->submitPdfExportData($data); } return $this; } public static function preparePdfPageHeader($partId, $revisionId = null, $headerSuffix = null) { $partObject = new App_Part_Obj(array('primaryKey' => $partId, 'revisionId' => $revisionId)); $partInfo = $partObject->getData(); $clientObject = new App_Client_Obj(array('primaryKey' => $partInfo['clientId'])); $partInfo['client'] = $clientObject->getData('name'); $revisionList = Qs_Array::get($partInfo, 'revisions'); // $partObject->getData('revisions'); $revisionById = Qs_Array::group($revisionList, 'id'); if ($revisionId && isset($revisionById[$revisionId])) { $revisionData = $revisionById[$revisionId]; } else { $revisionData = Qs_Array::group($revisionList, 'type')['current']; } $revisionPrefix = ($revisionData['preProduction'] == 'y') ? 'PP' : ''; $revision = $revisionPrefix . $revisionData['version']; $partNumber = App_Part_ExportObj::getPartNumber($partId); $placeholders = array( '{partNumber}' => $partNumber, '{revision}' => $revision, '{partClient}' => $partInfo['client'], '{partName}' => $partInfo['name'], '{headerSuffix}' => $headerSuffix ? ' > ' . $headerSuffix : '', ); return str_replace(array_keys($placeholders), array_values($placeholders), self::$_pdfPageHeaderPattern); } public static function preparePdfPageFooter() { $timestamp = mktime( intval(date('G')), // hour intval(date('i')), // minute 0, // second intval(date('n')), // month intval(date('j')) + 1 ); $placeholders = array( '{time}' => date('g:i a', $timestamp), '{date}' => date('j-M-Y', $timestamp), ); return str_replace(array_keys($placeholders), array_values($placeholders), self::$_pdfPageFooterPattern); } protected function _doPrint() { if (($limit = ini_get('max_execution_time')) && $limit < 180) { set_time_limit(180); // 3m } $partId = Qs_Request::getRequestValue('partId'); $mode = Qs_Request::getGetValue('mode'); // export last revision available to user if ('pdf' === $mode || 'pdfPrint' === $mode) { $partObject = new App_Part_Obj(array('primaryKey' => $partId)); $partData = $partObject->getData(); $pdfName = isset($partData['number']) ? $partData['number'] : $partId; if (null == ($revisionId = Qs_Request::getRequestValue('revisionId'))) { $revisionId = Qs_Array::get($partData, 'revision[id]'); } $setId = null; if (($processId = Qs_Request::getRequestValue('processId'))) { $this->dataObj->setPrimaryKey($processId)->initData(); $departmentId = (int) $this->dataObj->getData('departmentId'); $headerSuffix = $this->dataObj->getData('name'); $pdfName .= ',department-' . $departmentId; $pdfName .= ',process-' . $processId; if (($setId = Qs_Request::getRequestValue('setId'))) { $pdfName .= ',set-' . $setId; $sets = $this->dataObj->getSetIds($partId); $headerSuffix .= ' Set#' . $sets[$setId]; } } else { $headerSuffix = 'General Specification'; if ('0' === $processId) { $pdfName .= ',process-general_specifications'; } if (($departmentId = Qs_Request::getRequestValue('departmentId'))) { $pdfName .= ',department-' . $departmentId; $departmentObject = new App_Department_Obj(array('primaryKey' => $departmentId)); $headerSuffix = $departmentObject->getData('name'); } } $options = (array) Qs_Request::getGet(); unset($options['mode']); if ($revisionId) { $options['revisionId'] = $revisionId; } $url = $this->url($options); $pdfPageHeader = $this->preparePdfPageHeader($partId, $revisionId, $headerSuffix); $pdfPageFooter = ('pdfPrint' === $mode) ? $this->preparePdfPageFooter() : ''; $file = $pdfName; try { if (($file = App_Part_ExportView::renderPdf($url, $pdfName, $pdfPageHeader, $pdfPageFooter))) { if ('pdf' === $mode) { $this->_doSavePdfExportFile($file, $partId, $departmentId, $processId, $setId); } $this->_sendTempFile($file, $pdfName); } } catch (App_Part_Export_NotMovedException $e) { exit($e->createMessage()); } catch (Exception $e) { exit('Error: File "' . basename($file) . '" failed to export. ' . PHP_EOL . $e); } exit; } $revisionId = Qs_Request::getRequestValue('revisionId'); $this->_doc->addStylesheet('css/formBuilder.css'); $item = array('tpl' => $this->getTemplate('print.tpl'), 'processes' => array()); $this->_addItemInformation($partId, $item, $revisionId, true); if (null != ($processId = Qs_Request::getRequestValue('processId'))) { if ($processId) { $this->dataObj->setPrimaryKey($processId); $item['currentProcessTitle'] = $this->dataObj->initData()->getData('name'); $setId = Qs_Request::getRequestValue('setId'); $process = $this->_addProcess2Print($processId, $partId, $setId, $revisionId); $item['processes'] = array_merge($item['processes'], $process); if ($setId) { $sets = $this->dataObj->getSetIds($partId); $item['currentProcessTitle'] .= ' Set#' . $sets[$setId]; } } else { $item['processes'][] = new Qs_Doc_Item(array('isGeneralSpecification' => 'y')); $item['currentProcessTitle'] = 'General Specification'; } } else { if (null != ($departmentId = Qs_Request::getRequestValue('departmentId'))) { $departmentObject = new App_Department_Obj(array('primaryKey' => $departmentId)); $item['currentProcessTitle'] = $departmentObject->getData('name'); } $departmentObj = new App_Department_Obj(); $fullList = $departmentObj->getPartProcessList($partId, $departmentId); $processList = $this->_prepareProcessList($fullList['list']); $item['processes'][] = new Qs_Doc_Item(array('isGeneralSpecification' => 'y')); foreach ($processList as $processId) { $this->_setId = null; $process = $this->_addProcess2Print($processId, $partId, null, $revisionId); $item['processes'] = array_merge($item['processes'], $process); } } $this->_addItem($item); } protected function _prepareProcessList($list) { $processList = array(); foreach ($list as $item) { if ((int)$item['processId'] && $item['nonExport'] != 'y') { $processList[] = $item['processId']; } if (!empty($item['list'])) { $processList = array_merge($processList, $this->_prepareProcessList($item['list'])); } } return $processList; } protected function _getProcessPrintItem($processId, $partId, $setId = null, $revisionId = null) { $this->dataObj->setPrimaryKey($processId); $this->dataObj->clearData(); $this->_processData = $this->dataObj->getData(); $mediaList = $this->dataObj->getMediaList($this->dataObj->getPrimaryKey(), $partId, $revisionId); $partObj = new App_Part_Obj(array('primaryKey' => $partId, 'revisionId' => $revisionId)); if (null == $revisionId) { $partRevisionData = $partObj->getData('revision'); $revisionId = $partRevisionData['id']; } $process = $this->dataObj->initData()->getData(); if ($this->dataObj->getData('isMedia') == 'y') { $this->assignAnnotations($mediaList, $revisionId); $process['list'] = $mediaList; } else { $process['elements'] = $this->_getResultElements($partId, true, $revisionId, false, $setId); $process['partElements'] = $this->_getResultElements($partId, true, $revisionId, true, $setId); } $part = $this->dataObj->tablePart->search($partId); $process['partFormHeight'] = $part['height']; $sets = $this->dataObj->getSetIds($partId); $process['setTitle'] = empty($sets) ? '' : $sets[$setId]; return $process; } protected function _getSetId() { if (null === $this->_processData) { $this->_processData = $this->dataObj->getData(); }; if ($this->_processData['isMultiply'] == 'y' && null === $this->_setId) { $setIds = $this->dataObj->getSetIds(Qs_Request::getGetValue('partId')); $allSetIds = $this->dataObj->getSetIds(Qs_Request::getGetValue('partId'), 'setId', null, true); if (Qs_Request::getGetValue('setId')) { $this->_setId = Qs_Request::getGetValue('setId'); } elseif(Qs_Request::getPostValue('setId')) { $this->_setId = Qs_Request::getPostValue('setId'); } elseif (!empty($setIds)) { reset($setIds); $this->_setId = key($setIds); } $lastSetId = empty($allSetIds) ? null : max(array_keys($allSetIds)); if ($this->_setId != ($lastSetId + 1) && !empty($setIds) && !array_key_exists($this->_setId, $setIds)) { $this->_setId = max($setIds); } if ($this->_processData['isMultiply'] == 'y' && null === $this->_setId) { $this->_setId = self::FIRST_SET_ID; } } return $this->_setId; } /** * @param $processId * @param $partId * @param $setId * @param $revisionId * @return mixed */ protected function _addProcess2Print($processId, $partId, $setId = null, $revisionId = null) { $processes = array(); $this->dataObj->setPrimaryKey($processId); if (null === $setId) { $setIds = array_keys($this->dataObj->getSetIds($partId)); if (empty($setIds)) { $setIds[] = null; } } else { $setIds = array($setId); } foreach ($setIds as $setId) { $processes[] = new Qs_Doc_Item($this->_getProcessPrintItem($processId, $partId, $setId, $revisionId)); } return $processes; } }