Пример #1
0
 /**
  ** Function to display Policy documents categories
  ** Based on privileges for View/Manage Policy documents, categories are listed as menu items
  ** 1. get categories created for policy documents
  ** 2. build menu with respective urls
  **/
 public static function viewPolicyDocuments($call)
 {
     /**
      * Instantiate categories model
      * to get categories and documents count for each category
      **/
     $categoriesModel = new Default_Model_Categories();
     $dataObj = $categoriesModel->getCategories('menu');
     $categoriesObj = $documentsObj = '';
     $documentsCntArr = array();
     if (!empty($dataObj)) {
         $categoriesObj = $dataObj['res'];
         $documentsObj = $dataObj['docs'];
         /** 
          ** looping through documents object
          ** to build an array with category_id as index and documents count as value
          **/
         if (!empty($documentsObj)) {
             for ($i = 0; $i < sizeof($documentsObj); $i++) {
                 $documentsCntArr[$documentsObj[$i]['category_id']] = $documentsObj[$i]['doccnt'];
             }
         }
     }
     $html = '';
     /**
      ** looping through categories object
      ** to build menu items under Organization > Policy documents
      ** with documents count for each category/menu item
      **/
     if (!empty($categoriesObj)) {
         $html .= '    <ul>';
         for ($c = 0; $c < sizeof($categoriesObj); $c++) {
             $catId = $categoriesObj[$c]['id'];
             $url = BASE_URL . 'policydocuments/id/' . $catId;
             $html .= '<li menu-url="' . $url . '" parent-div="div_mchilds_' . ORGANIZATION . '" super-parent="main_parent_' . ORGANIZATION . '" class="clickable_menu set_over_text" primary_parent="' . POLICY_DOCUMENTS . '"><a href="' . ($call == 'menusettings' ? "javascript:void(0);" : $url) . '"><i class="span_sermenu">' . $categoriesObj[$c]['category'] . '</i> ';
             if (isset($documentsCntArr[$catId]) && !empty($documentsCntArr[$catId])) {
                 $html .= '<b class="super_cnt">' . $documentsCntArr[$catId] . '</b></a></li>';
             } else {
                 $html .= '<b class="super_cnt">0</b></a></li>';
             }
         }
         $html .= '    </ul>';
     }
     return $html;
 }
 /**
  **	this action is used to display edit form
  **  if post values are available will redirect to new policy document
  **/
 public function editAction()
 {
     /** capture document id to edit **/
     $docId = (int) $this->_request->getParam('id');
     /** check if document id is numeric 
      ** if yes, then get document details and populate the edit form
      ** if no, display no data message
      **/
     if (is_numeric($docId) && $docId > 0) {
         /**
          ** capturing referral URL, to redirect after adding policy document
          **/
         $redirectUrl = '';
         if (isset($_SERVER['HTTP_REFERER'])) {
             $httpReferrer = $_SERVER['HTTP_REFERER'];
             $redirectUrl = str_replace(BASE_URL, '', $httpReferrer);
             if (strpos($redirectUrl, 'edit') === false) {
                 $this->view->redirectUrl = $redirectUrl;
             }
         }
         /** Initiate document form **/
         $documentsAddForm = new Default_Form_Policydocuments();
         $this->view->form = $documentsAddForm;
         $this->view->userid = $this->loggedInUser;
         $documentsAddForm->setAttrib('action', BASE_URL . 'policydocuments/edit/id/' . $docId);
         /** get document details based on document id **/
         $res = $this->documentsModel->getDocumentsById($docId);
         if (!empty($res)) {
             /** populate edit form **/
             $documentsAddForm->populate($res);
             if ($res['file_name']) {
                 $new = array();
                 $ori = array();
                 $attachments = json_decode($res['file_name'], true);
                 foreach ($attachments as $k => $v) {
                     $new[] = $v["new_name"];
                     $ori[] = $v["original_name"];
                 }
                 $msg['file_original_names'] = implode(',', $ori);
                 $msg['file_new_names'] = implode(',', $new);
                 $this->view->msgarray = $msg;
                 $this->view->file_name = $res['file_name'];
             }
             /**
              ** to display "Add category" link, check add privileges for the logged in user 
              **/
             $popConfigPermission = array();
             if (sapp_Global::_checkprivileges(POLICY_DOCS_CATEGORIES, $this->loggedInUserGroup, $this->loggedInUserRole, 'add') == 'Yes') {
                 array_push($popConfigPermission, 'category');
             }
             $this->view->popConfigPermission = $popConfigPermission;
             /**
              ** Get all categories
              ** populate categories select control
              **/
             $categoriesModel = new Default_Model_Categories();
             $categoriesObj = $categoriesModel->getCategories('add');
             if (!empty($categoriesObj)) {
                 $documentsAddForm->category_id->addMultiOption('', 'Select Category');
                 foreach ($categoriesObj as $categories) {
                     $documentsAddForm->category_id->addMultiOption($categories['id'], utf8_encode($categories['category']));
                 }
             }
             $documentsAddForm->setDefault('category_id', $res['category_id']);
             $this->view->category_id = $res['category_id'];
             /** change submit button label to Update **/
             $documentsAddForm->submit->setLabel('Update');
             $this->view->ermsg = '';
             /**
              ** if post variables are available
              ** redirect to update function
              ** with form object and document id
              **/
             if ($this->getRequest()->getPost()) {
                 $this->update($documentsAddForm, $docId);
             }
         } else {
             $this->view->ermsg = 'nodata';
         }
         $this->view->id = $docId;
     } else {
         $this->view->ermsg = 'invalidUrl';
     }
 }