/**
  * IS: Parameter id terdeklarasi
  * FS: Mengirimkan ke viewer: pageTitle
  * Desc: Fungsi untuk generate breadcrumb
  */
 protected function _generateBreadcrumb()
 {
     // id_menu_material = 'Promotion Materials'
     $listTitle = $this->view->translate('id_menu_material');
     if ($this->_hasParam('id')) {
         // Param
         $materialId = $this->_getParam('id');
         // Model
         $materialDescDb = new Model_DbTable_MaterialDescription();
         // Data
         $materialTitle = $materialDescDb->getTitleById($materialId, $this->_languageId);
     }
     $texthomelink = $this->view->translate('id_menu_home');
     $links = null;
     switch ($this->_request->getActionName()) {
         case 'view':
             $links = array($texthomelink => $this->view->baseUrl('/'), $listTitle => $this->view->baseUrl('material'), $materialTitle => '');
             $this->view->pageTitle = $materialTitle;
             break;
         case 'detail':
             $links = array($texthomelink => $this->view->baseUrl('/'), $listTitle => $this->view->baseUrl('material'), $materialTitle => '');
             $this->view->pageTitle = $materialTitle;
             break;
         case 'index':
         default:
             $links = array($texthomelink => $this->view->baseUrl('/'), $listTitle => '');
             $this->view->pageTitle = $listTitle;
     }
     Zend_Registry::set('breadcrumb', $links);
 }
 /**
  * IS: Parameter id terdeklarasi
  * FS: Mengirimkan ke viewer: form, datamaterial, numbCtr2
  * Desc: Mengatur aksi yang dilakukan untuk halaman edit
  */
 public function editAction()
 {
     $material_id = $this->_getParam('id');
     $language_id = $this->_getParam('lang');
     $form = new Admin_Form_MaterialPromotionForm();
     $material = new Model_DbTable_Material();
     $materialdesc = new Model_DbTable_MaterialDescription();
     $materiallink = new Model_DbTable_MaterialLink();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $title = htmlspecialchars($_POST['materialTitle'], ENT_QUOTES);
             $desc = htmlspecialchars($_POST['materialDescription'], ENT_QUOTES);
             if ($language_id == 1) {
                 $indo = $materialdesc->checkForIndo($material_id, 1);
                 if ($indo) {
                     $data2 = array('material_id' => $material_id, 'language_id' => $language_id, 'title' => $title, 'description' => $desc);
                     $materialdesc->updateMaterial($data2, $material_id, $language_id);
                 } else {
                     $data2 = array('material_id' => $material_id, 'language_id' => $language_id, 'title' => $title, 'description' => $desc);
                     $materialdesc->insertMaterial($data2);
                 }
             } else {
                 $data = array('name' => $title);
                 $material->updateMaterial($data, $material_id);
                 $data2 = array('title' => $title, 'description' => $desc);
                 $materialdesc->updateMaterial($data2, $material_id, $language_id);
                 /** Counter jumlah material yang diupdate */
                 $numbCtr = $_POST['materialCtr'];
                 $no = 1;
                 for ($i = 1; $i <= $numbCtr; $i++) {
                     if (!empty($_POST['materialName' . $i]) and !empty($_POST['materialUrl' . $i])) {
                         $materialStack[$no]['file'] = $_POST['materialName' . $i];
                         $materialStack[$no]['link'] = $_POST['materialUrl' . $i];
                         $no++;
                     }
                 }
                 /** Get material list from database and convert to a NON ASSOC Array */
                 $listmaterial = $materiallink->getAllById($material_id);
                 if (!empty($listmaterial)) {
                     foreach ($listmaterial as $val) {
                         $oldmaterial[$val['file_number']]['file'] = $val['file'];
                         $oldmaterial[$val['file_number']]['link'] = $val['link'];
                     }
                 }
                 /**
                  * Compare new materials with old materials,
                  * if exist in new materials but not in old one, then insert
                  * if exist in old materials but not in new one, then delete
                  * if exist in both materials but different, then update
                  */
                 for ($i = 1; $i <= max(count($materialStack), count($oldmaterial)); $i++) {
                     if (!empty($materialStack[$i]) and !empty($oldmaterial[$i])) {
                         if ($materialStack[$i]['file'] != $oldmaterial[$i]['file'] or $materialStack[$i]['link'] != $oldmaterial[$i]['link']) {
                             $data3 = array('file' => $materialStack[$i]['file'], 'link' => $materialStack[$i]['link']);
                             $materiallink->updateMaterial($data3, $material_id, $i);
                         }
                     } else {
                         if (!empty($materialStack[$i]) and empty($oldmaterial[$i])) {
                             $data3 = array('material_id' => $material_id, 'file_number' => $i, 'file' => $materialStack[$i]['file'], 'link' => $materialStack[$i]['link']);
                             $materiallink->insertMaterial($data3);
                         } else {
                             if (empty($materialStack[$i]) and !empty($oldmaterial[$i])) {
                                 $materiallink->deleteMaterial($material_id, $i);
                             }
                         }
                     }
                 }
             }
             $this->loggingaction('promotionalmaterials', 'edit', $material_id);
             $this->_flash->addMessage('1\\Promotional Material Update Success!');
             $this->_redirect($this->view->rootUrl('/admin/materialpromotionindo/'));
         }
     }
     $data = $materiallink->getAllNameLinkByMaterialId($material_id);
     if ($language_id == 1) {
         $indo = $materialdesc->checkForIndo($material_id, 1);
         if ($indo) {
             $material_data = $materialdesc->getAllByIdLang($material_id);
         }
     } else {
         $material_data = $materialdesc->getAllByIdLang($material_id, 2);
     }
     $form->materialTitle->setValue($this->view->htmlDecode($material_data[0]['title']));
     $form->materialDescription->setValue($this->view->htmlDecode($material_data[0]['description']));
     /** send to view */
     $this->view->language_id = $language_id;
     $this->view->form = $form;
     $this->view->datamaterial = $data;
     $this->view->numbCtr = sizeof($data);
 }