public function getClassFiles($class) { $allClasses = Snep_SoundFiles_Manager::getClasses(); $classesFolder = array(); foreach ($allClasses as $id => $xclass) { $classesFolder[$id] = $id; } if (file_exists($class['directory'])) { $allFiles = array(); $files = array(); foreach (scandir($class['directory']) as $file) { if (!preg_match("/^\\.+.*/", $file) && !in_array($file, $classesFolder)) { if (preg_match("/^backup+.*/", $file)) { foreach (scandir($class['directory'] . '/' . $file) as $backup) { if (!preg_match("/^\\.+.*/", $backup)) { // $files[] = $class['directory'] .'/backup/'. $backup; } } } elseif (preg_match("/^tmp+.*/", $file)) { foreach (scandir($class['directory'] . '/' . $file) as $tmp) { if (!preg_match("/^\\.+.*/", $tmp)) { // $files[] = $class['directory'] .'/tmp/'. $tmp; } } } else { $files[$file] = $class['directory'] . '/' . $file; //$allFiles[$file] = $file; } } } $resultado = array(); foreach ($files as $name => $file) { $resultado[$name] = Snep_SoundFiles_Manager::get($name); $resultado[$name]['full'] = $file; } return $resultado; } }
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; }
/** * Edit Carrier */ public function editAction() { $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Sound Files"), $this->view->translate("Edit"))); $file = $this->_request->getParam("file"); $data = Snep_SoundFiles_Manager::get($file); $this->view->file = $data; $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('Sound Files'))->addValidator(new Zend_Validate_File_Extension(array('wav', 'gsm')))->removeDecorator('DtDdWrapper')->setIgnore(true); $form->addElement($file); $form->getElement('filename')->setValue($data['arquivo'])->setAttrib('readonly', true); $form->getElement('description')->setLabel($this->view->translate('Description'))->setValue($data['descricao'])->setRequired(true); if ($this->_request->getPost()) { $form_isValid = $form->isValid($_POST); $dados = $this->_request->getParams(); if ($form_isValid) { if ($_FILES['file']['name'] != "" && $_FILES['file']['size'] > 0) { $path_sound = Zend_Registry::get('config')->system->path->asterisk->sounds; $filepath = Snep_SoundFiles_Manager::verifySoundFiles($_POST['filename'], true); exec("mv {$filepath['fullpath']} {$path_sound}/backup/ "); exec("mv {$_FILES['file']['tmp_name']} {$filepath['fullpath']} "); } Snep_SoundFiles_Manager::edit($_POST); $this->_redirect($this->getRequest()->getControllerName()); } } $this->view->form = $form; }