public function del()
 {
     //apakah ada file
     $adafile = isset($_POST['id']) ? $_POST['id'] : '';
     //cek if ada file
     if ($adafile) {
         $if = new InputFileModel();
         $uploadpath = $if->upload_location;
         if (file_exists($uploadpath . $adafile)) {
             //delete old file
             if (unlink($uploadpath . $adafile)) {
                 $arrf = $if->getWhere("file_filename = '{$adafile}' LIMIT 0,1");
                 if (count($arrf) > 0) {
                     $if->delete($arrf[0]->file_id);
                 }
                 //delete from log
                 PortalFileLogger::deleteFileLog($uploadpath . $adafile);
                 //delete thumbs
                 if (file_exists($uploadpath . "thumbs/" . $adafile)) {
                     //delete old thumb file
                     unlink($uploadpath . "thumbs/" . $adafile);
                 }
             }
         }
     }
 }
 function deleteByGallery($gid)
 {
     global $db;
     $q = "SELECT * FROM {$this->table_name} WHERE gallery_id = '{$gid}'";
     $arr = $db->query($q, 2);
     $gw = new GalleryWeb();
     foreach ($arr as $car) {
         //delete di server
         $sc = unlink(_PHOTOPATH . $car->photo_filename);
         if ($sc) {
             unlink(_PHOTOPATH . "thumbnail/" . $car->photo_filename);
             //delete inputfilehistory
             $if = new InputFileModel();
             $arr = $if->getWhere("file_filename = '" . $car->photo_filename . "' LIMIT 0,1");
             $if = $arr[0];
             $if->delete($if->file_id);
         }
     }
     $q = "DELETE FROM {$this->table_name}  WHERE gallery_id = '{$gid}'";
     $db->query($q, 0);
 }
 public function uploadfiles()
 {
     //apakah ada file
     $adafile = isset($_GET['adafile']) ? $_GET['adafile'] : '';
     //cek if ada file
     if ($adafile) {
         $if = new InputFileModel();
         $uploadpath = $if->upload_location;
         if (file_exists($uploadpath . $adafile)) {
             //delete old file
             if (unlink($uploadpath . $adafile)) {
                 $arrf = $if->getWhere("file_filename = '{$adafile}' LIMIT 0,1");
                 if (count($arrf) > 0) {
                     $if->delete($arrf[0]->file_id);
                 }
                 //delete from log
                 PortalFileLogger::deleteFileLog($uploadpath . $adafile);
                 /*if(file_exists(_PHOTOPATH.'thumbnail/' . $adafile))
                   {
                       //delete old thumb file
                       unlink(_PHOTOPATH.'thumbnail/' . $adafile);
                   }*/
             }
         }
     }
     $data = array();
     //$tid = (isset($_GET['tid'])?addslashes($_GET['tid']):die('no ID'));
     $t = isset($_GET['t']) ? addslashes($_GET['t']) : die('no t');
     $data['files'] = $_GET['files'];
     $data['bool'] = 0;
     $dc = new InputFileModel();
     if (isset($_GET['files'])) {
         $error = false;
         $files = array();
         $uploaddir = $dc->upload_location;
         foreach ($_FILES as $file) {
             $f = new InputFileModel();
             $q = "INSERT INTO {$f->table_name} SET file_folder_id = '0',file_author = '" . Account::getMyID() . "'";
             global $db;
             $fid = $db->qid($q);
             $f->getByID($fid);
             if ($fid) {
                 $newname = $fid;
                 $f->file_url = basename($file['name']);
                 $ext = end(explode(".", $file['name']));
                 $f->file_ext = $ext;
                 $f->file_filename = $fid . "." . $ext;
                 $f->file_date = leap_mysqldate();
                 // if pdf
                 if (move_uploaded_file($file['tmp_name'], $uploaddir . $f->file_filename)) {
                     $files[] = $uploaddir . $file['name'];
                     $f->file_size = filesize($uploaddir . $f->file_filename);
                     if ($f->file_ext == "pdf") {
                         $a = new PDF2Text();
                         $a->setFilename($uploaddir . $f->file_filename);
                         $a->decodePDF();
                         $f->file_isi = preg_replace("/\r|\n/", " ", $a->output());
                         //the path to the PDF file
                         $strPDF = $uploaddir . $f->file_filename;
                         $thumb = $uploaddir . "thumbs/" . $fid . ".jpg";
                         exec("convert \"{$strPDF}[0]\" \"{$thumb}\"");
                     }
                     $f->load = 1;
                     $data['bool'] = $f->save();
                     $data['isImage'] = Leap\View\InputFile::isImage($f->file_filename);
                     $data['filename'] = $f->file_filename;
                     if (isset($_SESSION['target_id']['obj'])) {
                         $target = get_class($_SESSION['target_id']['obj']);
                     } else {
                         $target = "inputfile_unknown";
                     }
                     PortalFileLogger::save2log($uploaddir . $f->file_filename, $target, $f->file_url);
                     die(json_encode($data));
                 } else {
                     $error = true;
                 }
             }
         }
         $data = $error ? array('error' => 'There was an error uploading your files') : array('files' => $files);
     } else {
         $data = array('success' => 'Form was submitted', 'formData' => $_POST);
     }
     echo json_encode($data);
 }
 function pictureDelete()
 {
     $pid = isset($_GET['pid']) ? addslashes($_GET['pid']) : 0;
     if ($pid == 0) {
         die('No ID');
     }
     $car = new Galleryphoto();
     $car->getByID($pid);
     $car->delete($pid);
     //delete di server
     unlink(_PHOTOPATH . $car->photo_filename);
     unlink(_PHOTOPATH . "thumbnail/" . $car->photo_filename);
     //delete inputfilehistory
     $if = new InputFileModel();
     $arr = $if->getWhere("file_filename = '" . $car->photo_filename . "' LIMIT 0,1");
     $if = $arr[0];
     $if->delete($if->file_id);
 }