* @license    http://www.contenido.org/license/LIZENZ.txt
 * @link       http://www.4fb.de
 * @link       http://www.contenido.org
 * @since      file available since contenido release <= 4.6
 *
 * {@internal
 *   created 2003-03-27
 *   modified 2008-06-27, Frederic Schneider, add security fix
 *   modified 2010-08-18, Munkh-Ulzii Balidar, add a functionality to show the used info
 *
 *   $Id$:
 * }}
 *
 */
if (!defined('CON_FRAMEWORK')) {
    die('Illegal call');
}
$oLayouts = new cApiLayoutCollection();
$oLayouts->select("idclient = '$client'", '', 'name ASC');
$tpl->reset();
$tpl->set('s', 'SID', $sess->id);
$darkrow = false;
while ($layout = $oLayouts->next()) {
    if (!$perm->have_perm_area_action_item('lay_edit', 'lay_edit', $layout->get('idlay'))) {
        continue;
    }
    $name  = $layout->get('name');
    $descr = cString::nullToString($layout->get('description'));
    $idlay = $layout->get('idlay');
    if (strlen($descr) > 64) {
        $descr = substr($descr, 0, 64);
        $descr .= ' ..';
    }
    $tmp_mstr = '%s';
    $area = 'lay';
    $mstr = sprintf($tmp_mstr, 'right_top',
                               $sess->url("main.php?area=$area&frame=3&idlay=$idlay"),
                               'right_bottom',
                               $sess->url("main.php?area=lay_edit&frame=4&idlay=$idlay"),
                               $descr, $descr, $name);
    $tpl->set('d', 'NAME', $mstr);
    $inUse = $classlayout->layoutInUse($idlay);
    $bgColor = ($darkrow) ? $cfg['color']['table_dark'] : $cfg['color']['table_light'];
    $darkrow = !$darkrow;
    $tpl->set('d', 'BGCOLOR', $bgColor);
    if ((!$perm->have_perm_area_action_item('lay', 'lay_delete', $idlay)) && 
        (!$perm->have_perm_area_action('lay', 'lay_delete'))) {
        $delDescr = i18n("No permission");
    }
    if ($inUse) {
        $delDescr   = i18n("Layout is in use, cannot delete");
        $inUseDescr = i18n("Click for more information about usage");
        $inUseLink = ''
                   . ' ';
        $tpl->set('d', 'INUSE', $inUseLink);
    } else {
        $tpl->set('d', 'INUSE', '');
    }
    if ($perm->have_perm_area_action_item('lay', 'lay_delete', $idlay) && !$inUse) {
        $delTitle = i18n("Delete layout");
        $delDescr = sprintf(i18n("Do you really want to delete the following layout:
';
        $tpl->set('d', 'INUSE', $inUseLink);
    } else {
        $tpl->set('d', 'INUSE', '');
    }
    if ($perm->have_perm_area_action_item('lay', 'lay_delete', $idlay) && !$inUse) {
        $delTitle = i18n("Delete layout");
        $delDescr = sprintf(i18n("Do you really want to delete the following layout:
%s
"), clHtmlSpecialChars($name));
        $delLink  = ''
                  . ' ';
        $tpl->set('d', 'DELETE', $delLink);
    } else {
        $tpl->set('d', 'DELETE','
';
        $tpl->set('d', 'DELETE', $delLink);
    } else {
        $tpl->set('d', 'DELETE',' ');
    }
    $todo = new TODOLink('idlay', $idlay, i18n("Layout") . ': ' . $name, '');
    $tpl->set('d', 'TODO', $todo->render());
    if (filter_var($_REQUEST['idlay'], FILTER_SANITIZE_NUMBER_INT) == $idlay) {
        $tpl->set('d', 'ID', 'marked');
    } else {
        $tpl->set('d', 'ID', '');
    }
    $tpl->next();
}
//datas for show of used info per ajax
$tpl->set('s', 'AREA', $area);
$tpl->set('s', 'SESSION', $contenido);
$tpl->set('s', 'AJAXURL', $cfg['path']['contenido_fullhtml'].'ajaxmain.php');
$tpl->set('s', 'BOX_TITLE', i18n("The layout '%s' is used for following templates") . ":");
$tpl->generate($cfg['path']['templates'] . $cfg['templates']['lay_overview']);
?>
');
    }
    $todo = new TODOLink('idlay', $idlay, i18n("Layout") . ': ' . $name, '');
    $tpl->set('d', 'TODO', $todo->render());
    if (filter_var($_REQUEST['idlay'], FILTER_SANITIZE_NUMBER_INT) == $idlay) {
        $tpl->set('d', 'ID', 'marked');
    } else {
        $tpl->set('d', 'ID', '');
    }
    $tpl->next();
}
//datas for show of used info per ajax
$tpl->set('s', 'AREA', $area);
$tpl->set('s', 'SESSION', $contenido);
$tpl->set('s', 'AJAXURL', $cfg['path']['contenido_fullhtml'].'ajaxmain.php');
$tpl->set('s', 'BOX_TITLE', i18n("The layout '%s' is used for following templates") . ":");
$tpl->generate($cfg['path']['templates'] . $cfg['templates']['lay_overview']);
?>