function smarty_function_sync_folder($params, &$smarty) { global $site, $leht, $class_path; ############## # default values extract($params); //if(!isset($name)) { $name = 'folder'; } //eelista id'd if (isset($id)) { $id = (int) $id; $objekt = new Objekt(array('objekt_id' => $id)); //printr($objekt->all); //kui on album if ($objekt->all['tyyp_id'] == 16) { $conf = new CONFIG($objekt->all['ttyyp_params']); if ($folder_path = $conf->get('path')) { $folder_path = preg_replace('#^/#', '', $folder_path); $folder_path = preg_replace('#/$#', '', $folder_path); $folder_abs_path = $site->absolute_path . $folder_path; $sql = $site->db->prepare('select objekt_id from obj_folder where relative_path = ?', '/' . $folder_path); $result = new SQL($sql); if ($result->rows) { $id = $result->fetchsingle(); include_once $class_path . 'picture.inc.php'; generate_images($folder_abs_path, $conf->get('tn_size'), $conf->get('pic_size')); } else { //no such folder return; } } else { //no image folder set return; } } elseif ($objekt->all['tyyp_id'] != 22) { return; } } elseif (isset($path)) { $path = (string) $path; $path = preg_replace('#^/#', '', $path); $path = preg_replace('#/$#', '', $path); $sql = $site->db->prepare('select objekt_id from obj_folder where relative_path = ?', $path); $result = new SQL($sql); if ($result->rows) { $id = $result->fetchsingle(); } else { //no such folder return; } } include_once $class_path . 'adminpage.inc.php'; synchronise_folder($id); }
default: $sort_by = 'objekt.pealkiri'; break; } switch ($site->fdat['sort_dir']) { case 'asc': $sort_by .= ' asc'; break; case 'desc': $sort_by .= ' desc'; break; default: $sort_by .= ' asc'; break; } $synchro = synchronise_folder($folder_id); if ($synchro === true) { $files = get_files_from_folder($folder_id, $sort_by); $files = array('total_files' => $files['total_files'], 'files' => array(1 => $files['files'])); $folders = get_subfolders($folder_id); // dont send the parent itself reset($folders); unset($folders[key($folders)]); $response = array('error' => 0, 'folder_id' => $folder_id, 'files' => $files, 'folders' => $folders); } else { $response = array('error' => 1, 'error_message' => $synchro); } echo $json_encoder->encode($response); exit; } // upload file