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);
}
function add_image_to_album($file, $folder_path)
{
    global $site;
    $folder_path = trim($folder_path);
    // only public folders
    if (strpos($folder_path, 'public/') === 0) {
        $folder_id = create_folder_from_path($folder_path);
        if (is_int($folder_id)) {
            // upload the file
            $upload_result = upload_to_folder($file, $folder_id);
            if (is_int($upload_result)) {
                global $site, $class_path;
                $folder = new Objekt(array('objekt_id' => $folder_id));
                $conf = new CONFIG($folder->all['ttyyp_params']);
                include_once $class_path . 'picture.inc.php';
                generate_images($site->absolute_path . $conf->get('path'), $conf->get('tn_size'), $conf->get('pic_size'));
            }
            return $upload_result;
        } else {
            // error message
            return $folder_id;
        }
    } else {
        return 'no_such_folder';
    }
}
$ourbkcolor = new cColor($back_color);
// start out with a default zip name
$zippath = IMGPATH . "/" . basename(DEFAULTZIP, ".zip");
// check to see if a default zip file exists
$defaultzip = file_exists(IMGPATH . "/" . DEFAULTZIP);
// now, to go about rendering the button image!
// only bother rendering if we're referred here from ourself.
// people coming in from outside shouldn't have to wait for anything!
// if the url includes a cache identifier, use it
$neww = 0;
// worst case: we can't produce an image!
$newh = 0;
if (!empty($cachename)) {
    $zippath = IMGPATH . "/" . $cachename;
} elseif ($fromhere || !$defaultzip) {
    $zippath = generate_images($quality, $width_image, $height_image, $actwoa, $acthoa, $corner_radius, $color, $grcolor, $button_text, $text_height, $text_color, $back_color, $font_style, $rcolor, $rgrcolor, $rtext_color, $image_locate, $image_height, $image_name, $image_foreground, $image_foregroundcolor, $image_transparent, $image_transparentcolor, $fonts, $defaultzip);
    $neww = $actwoa;
    $newh = $acthoa;
} elseif (!$fromhere) {
    $zippath = IMGPATH . "/" . basename(DEFAULTZIP, ".zip");
    $dummy = "";
    // retrieve default image details from default.zip
    if (get_zip_data(basename($zippath), $dummy, $dummy, false, true, $dummy, $dummy, $data)) {
        $button_text = $data[TAGBT];
        $color = $data[TAGPC];
        $grcolor = $data[TAGGC];
        $width_image = $data[TAGW];
        $height_image = $data[TAGH];
        $corner_radius = $data[TAGCR];
        $text_height = $data[TAGTH];
        $text_color = $data[TAGTC];
                    exit;
                }
                $sql = $site->db->prepare("delete from obj_pilt where objekt_id = ?", $file['objekt_id']);
                new SQL($sql);
                $sql = $site->db->prepare("delete from document_parts where objekt_id = ?", $file['objekt_id']);
                new SQL($sql);
                $sql = $site->db->prepare("update objekt_objekt set parent_id = ? where objekt_id = ?", $folder_id, $file['objekt_id']);
                new SQL($sql);
                $sql = $site->db->prepare("update objekt set tyyp_id = 21 where objekt_id = ?", $file['objekt_id']);
                new SQL($sql);
                $sql = $site->db->prepare("insert into obj_file (objekt_id, relative_path, filename, size) values (?, ?, ?, ?)", $file['objekt_id'], '/' . $album_folder_path . '/' . $file['fail'], $file['fail'], $file['size']);
                new SQL($sql);
            }
            if ($images_result->rows) {
                // generate album images
                generate_images($site->absolute_path . $album_folder_path, $conf->get('tn_size') ? $conf->get('tn_size') : $site->CONF['thumb_width'], $conf->get('pic_size') ? $conf->get('pic_size') : $site->CONF['image_width']);
            }
            $conf->put('folder_id', $folder_id);
            $conf->put('path', $album_folder_path);
            $sql = $site->db->prepare("UPDATE objekt SET ttyyp_params = ? WHERE objekt_id=?", $conf->Export(), $album['objekt_id']);
            new SQL($sql);
        } else {
            echo '<font color=red>Error: could not create folder: ' . $album_folder_path . ', check filesystem permissions.</font>';
            exit;
        }
    }
}
// export documents from database to public/documents
$sql = 'select objekt_id, pealkiri, friendly_url, ttyyp_params from objekt where ttyyp_id = 11';
$result = new SQL($sql);
while ($document = $result->fetch('ASSOC')) {
function salvesta_objekt()
{
    global $site;
    global $objekt;
    verify_form_token();
    if ($objekt->objekt_id) {
        if ($objekt->on_sisu_olemas) {
            # -------------------------------
            # Objekti uuendamine andmebaasis
            # -------------------------------
            $sql = $site->db->prepare("update obj_rubriik set on_peida_vmenyy=?, on_printlink=?, on_meilinglist=? WHERE objekt_id=?", $objekt->all[on_peida_vmenyy], $site->fdat[on_printlink] ? 1 : 0, $site->fdat[on_meilinglist] ? 1 : 0, $objekt->objekt_id);
            $sth = new SQL($sql);
            $site->debug->msg($sth->debug->get_msgs());
        } else {
            # -------------------------------
            # Objekti loomine andmebaasis
            # -------------------------------
            $sql = $site->db->prepare("insert into obj_rubriik (objekt_id,on_peida_vmenyy, on_printlink, on_meilinglist) values (?,?,?,?)", $objekt->objekt_id, $objekt->all[on_peida_vmenyy], $site->fdat[on_printlink] ? 1 : 0, $site->fdat[on_meilinglist] ? 1 : 0);
            $sth = new SQL($sql);
            $site->debug->msg($sth->debug->get_msgs());
            // Here we make objekt_id like current id (in main window)
            ?>
			<script language=javascript><!--		
				variableFromEditRubriik_id='<?php 
            echo $objekt->objekt_id;
            ?>
';
			//--></script>
<?php 
        }
        $site->debug->msg("sisu on salvestatud, objekt_id = " . $objekt->objekt_id);
        #$site->debug->print_hash($site->fdat,1,"FDAT");
    } else {
        $site->debug->msg("sisu pole salvestatud kuna objekt_id puudub");
    }
    ############################
    ### image and thumb generation
    if ($site->fdat['old_tn_size'] != $site->fdat['tn_size'] || $site->fdat['old_path'] != $site->fdat['path'] || $site->fdat['old_pic_size'] != $site->fdat['pic_size'] || $site->fdat['op2'] == 'save') {
        if ($site->fdat['path']) {
            global $class_path;
            include_once $class_path . 'picture.inc.php';
            generate_images($site->absolute_path . $site->fdat['path'], $site->fdat['tn_size'], $site->fdat['pic_size']);
        }
    }
    ### end image and thumb generation
    ############################
}
 function refresh_gallery_images(&$objekt, $dir)
 {
     global $site, $class_path;
     include_once $class_path . 'picture.inc.php';
     // find album objects where the parent folder of the file is used
     $sql = "select ttyyp_params from objekt where tyyp_id = 16 and ttyyp_params like '%path = " . mysql_real_escape_string($dir) . "\n%' limit 1";
     $result = new SQL($sql);
     while ($ttyyp_params = $result->fetchsingle()) {
         $conf = new CONFIG($ttyyp_params);
         $conf->get('');
         generate_images($site->absolute_path . $conf->get('path'), $conf->get('tn_size'), $conf->get('pic_size'));
     }
 }