/** * Edit file form (use Ajax) * * @param integer $id File id * @return void */ public function edit($id) { // load dictionaries $this->dict->get_wordarray(array('form', 'files')); // get object $mod = new File_model(); $file = $mod->get_by_id($id); // builde the form $fields = array(); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $id, 'name' => 'id'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $file->id_area, 'name' => 'id_area'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $file->xtype, 'name' => 'xtype'); $area = $mod->get_by_id($file->id_area, 'areas'); switch ($file->xtype) { case 0: // image $folder = X4Files_helper::get_type_by_name($file->name, true); $action = file_exists(APATH . 'files/filemanager/img/' . $file->name) ? '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole"> <img class="thumb" src="' . FPATH . $folder . '/' . $file->name . '?t=' . time() . '" alt="' . $file->alt . '" /> </div><div class="one-half xs-one-whole"> <a class="btb" href="' . BASE_URL . 'files/editor/' . $file->id . '" title="' . _IMAGE_EDIT . '"><i class="fa fa-file-image-o fa-lg"></i> ' . _IMAGE_EDIT . '</a> </div></div>' : ''; break; case 2: // video $action = file_exists(APATH . 'files/filemanager/media/' . $file->name) ? '<div class="band inner-pad clearfix"><div class="one-whole"> <a class="btb" href="' . BASE_URL . 'files/editor/' . $file->id . '" title="' . _VIDEO_EDIT . '"><i class="fa fa-file-video-o fa-lg"></i> ' . _VIDEO_EDIT . '</a> </div></div>' : ''; break; case 3: // template $action = file_exists(APATH . 'files/filemanager/template/' . $file->name) ? '<div class="band inner-pad clearfix"><div class="one-whole"> <a class="btb" href="' . BASE_URL . 'files/editor/' . $file->id . '" title="' . _TEMPLATE_EDIT . '"><i class="fa fa-file-code-o fa-lg"></i> ' . _TEMPLATE_EDIT . '</a> </div></div>' : ''; break; default: // generic files $ext = pathinfo(APATH . 'files/filemanager/files/' . $file->name, PATHINFO_EXTENSION); if ($ext == 'txt' || $ext == 'csv') { $action = '<p><a class="btb" href="' . BASE_URL . 'files/editor/' . $file->id . '" title="' . _TEXT_EDIT . '"><i class="fa fa-file-text-o fa-lg"></i> ' . _TEXT_EDIT . '</a></p>'; } else { $action = ''; } break; } $fields[] = array('label' => null, 'type' => 'html', 'value' => '<p><b>' . $area->title . '</b>: ' . $file->name . '</p>' . $action); $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">'); $fields[] = array('label' => _CATEGORY, 'type' => 'text', 'value' => $file->category, 'name' => 'category', 'extra' => 'class="large"', 'rule' => 'required'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">'); $fields[] = array('label' => _SUBCATEGORY, 'type' => 'text', 'value' => $file->subcategory, 'name' => 'subcategory', 'extra' => 'class="large"', 'rule' => 'required'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>'); $fields[] = array('label' => _COMMENT, 'type' => 'textarea', 'value' => $file->alt, 'name' => 'alt'); // if submitted if (X4Route_core::$post) { $e = X4Validation_helper::form($fields, 'editor'); if ($e) { $this->editing($_POST); } else { $this->notice($fields); } die; } // contents $view = new X4View_core('editor'); $view->title = _EDIT_FILE; // form builder $view->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\');"'); if (!empty($action)) { $view->js = ' <script> window.addEvent("domready", function() { buttonize("simple-modal", "btb", "topic"); }); </script>'; } $view->render(TRUE); }