Ejemplo n.º 1
0
 /**
  * Register New files form data
  *
  * @access	private
  * @param   array 	$_post _POST array
  * @param   array 	$file_array Files labels array
  * @return  void
  */
 private function adding($_post, $file_array)
 {
     $msg = null;
     // check permission
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_file_upload', 0, 4);
     if (is_null($msg)) {
         $error = array();
         $mod = new File_model();
         $path = $mod->file_path;
         $filename = X4Files_helper::upload('xname', $path);
         // check for errors
         if ($filename[1]) {
             $post = array();
             $files = $filename[0];
             $n = sizeof($files);
             // handle _post for each area
             for ($i = 0; $i < $n; $i++) {
                 $xtype = X4Files_helper::get_type_by_name($files[$i]);
                 $areas = array();
                 foreach ($_post['id_area'] as $ii) {
                     $areas[] = $ii;
                     $post[] = array('id_area' => $ii, 'xtype' => $xtype, 'category' => X4Utils_helper::unspace($_post['category']), 'subcategory' => X4Utils_helper::unspace($_post['subcategory']), 'name' => $files[$i], 'alt' => $_POST['dida_' . ($i + 1)], 'xon' => 1);
                 }
             }
             // insert new files
             $result = $mod->insert_file($post);
             if ($result[1]) {
                 // add permission
                 $perm = new Permission_model();
                 foreach ($areas as $i) {
                     $perm->refactory_table($_SESSION['xuid'], array($i), 'files');
                 }
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'files/index/' . $post[0]['id_area'] . '/' . urlencode($post[0]['category']) . '/' . urlencode($post[0]['subcategory']), 'title' => null);
             }
         } else {
             // build msg
             $str = array();
             foreach ($filename[0] as $k => $v) {
                 // each field
                 foreach ($v as $i) {
                     // each error
                     $str[] = $file_array[$k] . _TRAIT_ . $this->dict->get_word(strtoupper($i), 'msg');
                 }
             }
             $msg = AdmUtils_helper::set_msg(false, '', implode('<br />', $str));
         }
     }
     $this->response($msg);
 }