function tplsadmin_copy_templates_f2db($tplset_to, $whr_append = '1')
{
    global $db;
    // get tplsource
    $result = $db->query("SELECT * FROM " . $db->prefix("tplfile") . "  WHERE tpl_tplset='default' AND ({$whr_append})");
    while ($row = $db->fetchArray($result)) {
        $basefilepath = tplsadmin_get_basefilepath($row['tpl_module'], $row['tpl_type'], $row['tpl_file']);
        $tpl_source = rtrim(implode("", file($basefilepath)));
        $lastmodified = filemtime($basefilepath);
        $drs = $db->query("SELECT tpl_id FROM " . $db->prefix("tplfile") . " WHERE tpl_tplset='" . addslashes($tplset_to) . "' AND ({$whr_append}) AND tpl_file='" . addslashes($row['tpl_file']) . "' AND tpl_refid='" . addslashes($row['tpl_refid']) . "'");
        if (!$db->getRowsNum($drs)) {
            // INSERT mode
            $sql = "INSERT INTO " . $db->prefix("tplfile") . " SET tpl_refid='" . addslashes($row['tpl_refid']) . "',tpl_desc='" . addslashes($row['tpl_desc']) . "',tpl_lastmodified='" . addslashes($lastmodified) . "',tpl_type='" . addslashes($row['tpl_type']) . "',tpl_tplset='" . addslashes($tplset_to) . "',tpl_file='" . addslashes($row['tpl_file']) . "',tpl_module='" . addslashes($row['tpl_module']) . "'";
            $db->query($sql);
            $tpl_id = $db->getInsertId();
            $db->query("INSERT INTO " . $db->prefix("tplsource") . " SET tpl_id='{$tpl_id}', tpl_source='" . addslashes($tpl_source) . "'");
            altsys_template_touch($tpl_id);
        } else {
            while (list($tpl_id) = $db->fetchRow($drs)) {
                // UPDATE mode
                $db->query("UPDATE " . $db->prefix("tplfile") . " SET tpl_lastmodified='" . addslashes($lastmodified) . "' WHERE tpl_id='{$tpl_id}'");
                $db->query("UPDATE " . $db->prefix("tplsource") . " SET tpl_source='" . addslashes($tpl_source) . "' WHERE tpl_id='{$tpl_id}'");
                altsys_template_touch($tpl_id);
            }
        }
    }
}
    }
    altsys_template_touch($tpl_id);
    // continue or end ?
    redirect_header('index.php?mode=admin&lib=altsys&page=mytplsadmin&dirname=' . $tpl['tpl_module'], 1, _MD_A_MYTPLSFORM_CREATED);
    exit;
}
//****************//
//   FORM stage   //
//****************//
xoops_cp_header();
$mymenu_fake_uri = 'index.php?mode=admin&lib=altsys&page=mytplsadmin&dirname=' . $mydirname;
// mymenu
altsys_include_mymenu();
echo "<h3 style='text-align:" . _GLOBAL_LEFT . ";'>" . _MD_A_MYTPLSFORM_EDIT . " : " . htmlspecialchars($tpl['tpl_type'], ENT_QUOTES) . " : " . htmlspecialchars($tpl['tpl_file'], ENT_QUOTES) . " (" . htmlspecialchars($tpl['tpl_tplset'], ENT_QUOTES) . ")</h3>\n";
// diff from file to selected DB template
$basefilepath = tplsadmin_get_basefilepath($tpl['tpl_module'], $tpl['tpl_type'], $tpl['tpl_file']);
$diff_from_file4disp = '';
if (file_exists($basefilepath)) {
    $original_error_level = error_reporting();
    error_reporting($original_error_level & ~E_NOTICE & ~E_WARNING);
    $diff =& new Text_Diff(file($basefilepath), explode("\n", $tpl['tpl_source']));
    $renderer =& new Text_Diff_Renderer_unified();
    $diff_str = htmlspecialchars($renderer->render($diff), ENT_QUOTES);
    foreach (explode("\n", $diff_str) as $line) {
        if (ord($line) == 0x2d) {
            $diff_from_file4disp .= "<span style='color:red;'>" . $line . "</span>\n";
        } else {
            if (ord($line) == 0x2b) {
                $diff_from_file4disp .= "<span style='color:blue;'>" . $line . "</span>\n";
            } else {
                $diff_from_file4disp .= $line . "\n";
Example #3
0
echo "<h3 style='text-align:" . _GLOBAL_LEFT . ";'>" . _MYTPLSADMIN_H3_MODULE . " : {$target_mname}</h3>\n";
// link to create a new custom template
if ($target_dirname == '_custom') {
    echo "<a href='index.php?mode=admin&lib=altsys&page=mytplsform&tpl_tplset=default'>" . _MYTPLSADMIN_CREATENEWCUSTOMTEMPLATE . "</a>\n";
}
// beggining of table & form
echo "\n\t<form name='MainForm' action='?mode=admin&amp;lib=altsys&amp;page=mytplsadmin&amp;dirname=" . htmlspecialchars($target_dirname, ENT_QUOTES) . "' method='post'>\n\t" . $xoopsGTicket->getTicketHtml(__LINE__) . "\n\t<table class='outer'>\n\t\t<tr>\n\t\t\t<th>" . _MYTPLSADMIN_TH_NAME . "</th>\n\t\t\t<th>" . _MYTPLSADMIN_TH_TYPE . "</th>\n\t\t\t<th><input type='checkbox' title=" . _MYTPLSADMIN_TITLE_CHECKALL . " onclick=\"with(document.MainForm){for(i=0;i<length;i++){if(elements[i].type=='checkbox'&&elements[i].name.indexOf('basecheck')>=0){elements[i].checked=this.checked;}}}\" />" . _MYTPLSADMIN_TH_FILE . "</th>\n\t\t\t{$tplsets_th4disp}\n\t\t</tr>\n";
// STYLE for distinguishing fingerprints
$fingerprint_styles = array('', 'background-color:#00FF00', 'background-color:#00CC88', 'background-color:#00FFFF', 'background-color:#0088FF', 'background-color:#FF8800', 'background-color:#0000FF', 'background-color:#FFFFFF');
// template ROWS
while (list($tpl_file, $tpl_desc, $type, $count) = $db->fetchRow($frs)) {
    $evenodd = @$evenodd == 'even' ? 'odd' : 'even';
    // information about the template
    echo "\n\t\t<tr>\n\t\t\t<td class='{$evenodd}'>\n\t\t\t\t<dl>\n\t\t\t\t\t<dt>" . htmlspecialchars($tpl_file, ENT_QUOTES) . "</dt>\n\t\t\t\t\t<dd>" . htmlspecialchars($tpl_desc, ENT_QUOTES) . "</dd>\n\t\t\t\t</dl>\n\t\t\t</td>\n\t\t\t<td class='{$evenodd}'>" . $type . "<br />(" . $count . ")</td>\n";
    // the base file template column
    $basefilepath = tplsadmin_get_basefilepath($target_dirname, $type, $tpl_file);
    if (file_exists($basefilepath)) {
        $fingerprint = tplsadmin_get_fingerprint(file($basefilepath));
        $fingerprints[$fingerprint] = 1;
        echo "<td class='{$evenodd}'>" . formatTimestamp(filemtime($basefilepath), 'm') . '<br />' . substr($fingerprint, 0, 16) . "<br /><input type='checkbox' name='basecheck[{$tpl_file}]' value='1' /></td>\n";
        $fingerprint_style_count = 0;
    } else {
        echo "<td class='{$evenodd}'><br /></td>";
        $fingerprint_style_count = -1;
    }
    // db template columns
    foreach ($tplsets as $tplset) {
        $tplset4disp = htmlspecialchars($tplset, ENT_QUOTES);
        // query for templates in db
        $drs = $db->query("SELECT * FROM " . $db->prefix("tplfile") . " f NATURAL LEFT JOIN " . $db->prefix("tplsource") . " s WHERE tpl_file='" . addslashes($tpl_file) . "' AND tpl_tplset='" . addslashes($tplset) . "'");
        $numrows = $db->getRowsNum($drs);