Beispiel #1
0
 public function editfileAction()
 {
     $fileName = $this->_request->getParam('file');
     $class = $this->_request->getParam('class');
     $className = Snep_SoundFiles_Manager::getClasse($class);
     $files = Snep_SoundFiles_Manager::getClassFiles($className);
     $_files = array('arquivo' => '', 'descricao' => '', 'tipo' => '', 'secao' => $class, 'full' => '');
     foreach ($files as $name => $file) {
         if ($name == $fileName) {
             if (isset($file['arquivo'])) {
                 $_files = $file;
             }
         }
     }
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Music on Hold Sessions"), $this->view->translate("Edit File"), $className));
     $form = new Snep_Form(new Zend_Config_Xml("modules/default/forms/sound_files.xml"));
     $form->setAction($this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . "/editfile/file/{$fileName}/class/{$class}");
     $file = new Zend_Form_Element_File('file');
     $file->setLabel($this->view->translate('Sound File'))->addValidator(new Zend_Validate_File_Extension(array('wav', 'gsm')))->removeDecorator('DtDdWrapper')->setIgnore(true);
     $form->addElement($file);
     $form->getElement('description')->setValue($_files['descricao']);
     $section = new Zend_Form_Element_Hidden('section');
     $section->setValue($_files['secao']);
     $form->addElement($section);
     $originalName = new Zend_Form_Element_Hidden('originalName');
     $originalName->setValue($fileName);
     $form->addElement($originalName);
     $originalPath = new Zend_Form_Element_Hidden('originalPath');
     $originalPath->setValue($_files['full']);
     $form->addElement($originalPath);
     $form->removeElement('type');
     if ($this->_request->getPost()) {
         $class = Snep_SoundFiles_Manager::getClasse($_POST['section']);
         $form_isValid = $form->isValid($_POST);
         $dados = $this->_request->getParams();
         $invalid = array('â', 'ã', 'á', 'à', 'ẽ', 'é', 'è', 'ê', 'í', 'ì', 'ó', 'õ', 'ò', 'ú', 'ù', 'ç', " ", '@', '!');
         $valid = array('a', 'a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'o', 'u', 'u', 'c', "_", '_', '_');
         if ($_FILES['file']['size'] > 0) {
             $oldName = $_POST['originalName'];
             $originalName = str_replace($invalid, $valid, $_FILES['file']['name']);
             $files = Snep_SoundFiles_Manager::get($originalName);
             if ($files) {
                 $file->addError($this->view->translate("The file already exists"));
                 $form_isValid = false;
             }
             if ($form_isValid) {
                 $uploadName = $_FILES['file']['tmp_name'];
                 $arq_tmp = $class['directory'] . "/tmp/" . $originalName;
                 $arq_dst = $class['directory'] . "/" . $originalName;
                 $arq_bkp = $class['directory'] . "/backup/" . $originalName;
                 $arq_orig = $class['directory'] . "/" . $originalName;
                 exec("mv {$uploadName} {$arq_tmp}");
                 $fileNe = basename($arq_dst, 'wav');
                 if ($_POST['gsm']) {
                     exec("sox {$arq_tmp} -r 8000 {$fileNe}.gsm");
                     $exists = file_exists($fileNe . "gsm");
                 } else {
                     exec("sox {$arq_tmp} -r 8000 -c 1 -e signed-integer -b 16 {$arq_dst}");
                     $exists = file_exists($arq_dst);
                 }
             }
             if ($exists) {
                 exec("rm -f {$_POST['originalPath']}");
                 Snep_SoundFiles_Manager::remove($oldName);
                 Snep_SoundFiles_Manager::add(array('arquivo' => $originalName, 'descricao' => $dados['description'], 'data' => new Zend_Db_Expr('NOW()'), 'tipo' => 'MOH', 'secao' => $dados['section']));
             }
         } else {
             $originalName = $_POST['originalName'];
             Snep_SoundFiles_Manager::editClassFile(array('arquivo' => $originalName, 'descricao' => $dados['description'], 'data' => new Zend_Db_Expr('NOW()'), 'tipo' => 'MOH', 'secao' => $dados['section']));
         }
         $this->_redirect($this->getRequest()->getControllerName() . "/file/class/{$className['name']}/");
     }
     $this->view->form = $form;
 }
Beispiel #2
0
 /**
  *  Add Sound File
  */
 public function addAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Sound Files"), $this->view->translate("Add")));
     $form = new Snep_Form(new Zend_Config_Xml("modules/default/forms/sound_files.xml"));
     $file = new Zend_Form_Element_File('file');
     $file->setLabel($this->view->translate('Select the file'))->addValidator(new Zend_Validate_File_Extension(array('wav', 'gsm')))->removeDecorator('DtDdWrapper')->setIgnore(true)->setRequired(true);
     $form->addElement($file);
     $form->removeElement('filename');
     if ($this->_request->getPost()) {
         $form_isValid = $form->isValid($_POST);
         $dados = $this->_request->getParams();
         if ($form_isValid) {
             $description = $_POST['description'];
             $gsmConvert = $_POST['gsm'];
             $type = 'AST';
             $invalid = array('â', 'ã', 'á', 'à', 'ẽ', 'é', 'è', 'ê', 'í', 'ì', 'ó', 'õ', 'ò', 'ú', 'ù', 'ç', " ", '@', '!');
             $valid = array('a', 'a', 'a', 'a', 'e', 'e', 'e', 'e', 'i', 'i', 'o', 'o', 'o', 'u', 'u', 'c', "_", '_', '_');
             $originalName = str_replace($invalid, $valid, $_FILES['file']['name']);
             $uploadName = $_FILES['file']['tmp_name'];
             $path_sound = Zend_Registry::get('config')->system->path->asterisk->sounds;
             $arq_tmp = $path_sound . "/tmp/" . $originalName;
             $arq_dst = $path_sound . "/" . $originalName;
             $arq_bkp = $path_sound . "/backup/" . $originalName;
             $arq_orig = $path_sound . "/pt_BR/" . $originalName;
             $exist = Snep_SoundFiles_Manager::get($originalName);
             if ($exist) {
                 $form->getElement('file')->addError($this->view->translate('File already exists'));
                 $form_isValid = false;
             } else {
                 if (!move_uploaded_file($uploadName, $arq_tmp)) {
                     throw new ErrorException($this->view->translate("Unable to move file"));
                 }
                 if ($_POST['gsm']) {
                     $fileNe = $path_sound . '/' . basename($arq_dst, '.wav') . '.gsm';
                     exec("sox {$arq_tmp} -r 8000 {$fileNe}");
                     $originalName = basename($originalName, '.wav') . ".gsm";
                 } else {
                     exec("sox {$arq_tmp} -r 8000 -c 1 -e signed-integer -b 16 {$arq_dst}");
                 }
                 if (file_exists($arq_dst) || file_exists($fileNe)) {
                     Snep_SoundFiles_Manager::add(array('arquivo' => $originalName, 'descricao' => $description, 'tipo' => 'AST'));
                     $this->_redirect($this->getRequest()->getControllerName());
                 } else {
                     $this->view->error = array('error' => 1, 'message' => $this->view->translate('Invalid Format'));
                 }
             }
         }
     }
     $this->view->form = $form;
 }