function mod_save($idmod_in, $name, $verbose, $description, $modversion, $modcat, $input, $output, $idclient, $repid = '', $sql_install = '', $sql_uninstall = '', $sql_update = '', $mod_rebuild_sql = false, $source_id = '0', $mod_no_wedding = false, $stripe = false, $mod_config_takeover = false) { global $db, $auth, $cms_db, $cfg_cms, $cms_lang, $cfg_client, $rep, $perm; global $idmod; //make global for header redirect $idmod = $idmod_in; // Eintrag in 'mod' Tabelle if (empty($name) || $name == '') { $name = $cms_lang['mod_defaultname']; } if (empty($modversion) || $modversion == '') { $modversion = '1.0'; } if ($stripe == 1) { $name = make_string_dump($name); $verbose = make_string_dump($verbose); $description = make_string_dump($description); $modversion = make_string_dump($modversion); $modcat = make_string_dump($modcat); $input = make_string_dump($input); $output = make_string_dump($output); } elseif ($stripe != 2) { set_magic_quotes_gpc($name); set_magic_quotes_gpc($verbose); set_magic_quotes_gpc($description); set_magic_quotes_gpc($modversion); set_magic_quotes_gpc($modcat); set_magic_quotes_gpc($input); set_magic_quotes_gpc($output); } $checked = ($err_i = $rep->mod_test(cms_stripslashes($input), $idmod)) || ($err_0 = $rep->mod_test(cms_stripslashes($output), $idmod)) ? '0' : '1'; $modverbose = $verbose == '-1' ? $name : $verbose; $mod_sql_uninstall = $sql_uninstall; $mod_sql_install = $sql_install; $sql_install = mysql_escape_string($rep->decode_sql($sql_install)); $sql_uninstall = mysql_escape_string($rep->decode_sql($sql_uninstall)); $sql_update = mysql_escape_string($rep->decode_sql($sql_update)); if ($mod_no_wedding == true) { $source_id = 0; $repositoryid = $rep->gen_new_mod($name); $update_source = ", source_id='0'"; } elseif ($source_id) { $repositoryid = $rep->gen_new_mod($name, true); } elseif ($repid == '') { $repositoryid = $rep->gen_new_mod($name); if ($errno = $rep->error(true)) { return $errno; } } else { $repositoryid = $rep->gen_new_mod($name, true); } if ($errno = $rep->error(true)) { return $errno; } elseif (empty($input) && empty($output)) { return '0424'; } if (!$idmod) { // Modul existiert noch nicht $sql = "INSERT INTO\r\n\t\t\t\t" . $cms_db['mod'] . "\r\n\t\t\t\t(name, description, version, cat, input, output, idclient, author, created, lastmodified,\r\n\t\t\t\trepository_id, install_sql, uninstall_sql, update_sql, source_id, verbose, checked)\r\n\t\t\t\tVALUES\r\n\t\t\t\t('{$name}', '{$description}', '{$modversion}', '{$modcat}', '{$input}', '{$output}', '{$idclient}',\r\n\t\t\t\t'" . $auth->auth['uid'] . "', '" . time() . "', '" . time() . "', '{$repositoryid}', '{$sql_install}', '{$sql_uninstall}', '{$sql_update}', '{$source_id}', '{$modverbose}', '{$checked}')"; $affect = $db->query($sql); if (!$affect || $affect < 1) { return '0400'; } $idmod = $last_id = $db->insert_id(); if ($mod_config_takeover == true) { $modul = $rep->mod_data($source_id, $idclient); mod_save_config($idmod, make_string_dump($modul['config'])); } // Event fire_event('mod_new', array('idmod' => $idmod, 'name' => $name)); } else { // hat sich das Modul geändert? $sql = "SELECT output FROM " . $cms_db['mod'] . " WHERE idmod='{$idmod}'"; $db->query($sql); $db->next_record(); $output_old = $db->f('output'); set_magic_quotes_gpc($output_old); //don't change verbose name by sql update if ($verbose == '-2') { $sql_verbose_name = ''; } else { $sql_verbose_name = "verbose = '{$modverbose}',"; } if ($output != $output_old) { $sql = "UPDATE " . $cms_db['mod'] . "\r\n\t\t\t\t\tSET\r\n\t\t\t\t\tname='{$name}', description='{$description}', version = '{$modversion}', cat = '{$modcat}',\r\n\t\t\t\t\tinput='{$input}', output='{$output}', author='" . $auth->auth['uid'] . "', lastmodified='" . time() . "',\r\n\t\t\t\t\tinstall_sql ='{$sql_install}', uninstall_sql ='{$sql_uninstall}', update_sql ='{$sql_update}' {$update_source}, repository_id = '{$repositoryid}', {$sql_verbose_name} checked = '{$checked}'\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\tidmod='{$idmod}'"; $db->query($sql); $change = 'true'; } else { $sql = "UPDATE " . $cms_db['mod'] . "\r\n\t\t\t\t\tSET\r\n\t\t\t\t\tname='{$name}', description='{$description}', version = '{$modversion}', cat = '{$modcat}', input='{$input}',\r\n\t\t\t\t\tauthor='" . $auth->auth['uid'] . "', lastmodified='" . time() . "', install_sql='{$sql_install}',\r\n\t\t\t\t\tuninstall_sql='{$sql_uninstall}', update_sql='{$sql_update}' {$update_source}, repository_id = '{$repositoryid}', {$sql_verbose_name} checked = '{$checked}'\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\tidmod='{$idmod}'"; $db->query($sql); } // Event fire_event('mod_edit', array('idmod' => $idmod, 'name' => $name)); } if ($idclient > 0 && $mod_sql_install != '' && $mod_rebuild_sql == true) { if ($mod_sql_uninstall != '') { $error = $rep->bulk_sql($mod_sql_uninstall); } if (!$error) { $error = $rep->bulk_sql($mod_sql_install); } if (!$error) { $sql = "UPDATE " . $cms_db['mod'] . " SET is_install='1', lastmodified='" . time() . "' WHERE idmod='{$idmod}'"; $db->query($sql); } // Event fire_event('mod_install_sql', array('idmod' => $idmod, 'name' => $name)); } if ($change) { // Status der 'code' Tabelle ändern $list = get_idtplconf_by_using_type($idmod, 'mod'); $list = get_idcode_by_idtplconf($list); change_code_status($list, '1'); unset($list); } // Rechte setzen if ($perm->have_perm('6', 'mod', $idmod)) { global $cms_gruppenids, $cms_gruppenrechte, $cms_gruppenrechtegeerbt, $cms_gruppenrechteueberschreiben; $perm->set_group_rights('mod', $idmod, $cms_gruppenids, $cms_gruppenrechte, $cms_gruppenrechtegeerbt, $cms_gruppenrechteueberschreiben, '', 0xafd); } return !$error ? '0412' : $error; }
function tpl_save($idtpl, $idlay, $tplname, $description, $tpl_overwrite_all) { global $db, $auth, $client, $cms_db, $cms_lang, $cfg_client, $tpl, $perm; global $idtpl; // Eintrag in 'tpl' Tabelle if ($tplname == '') { $tplname = $cms_lang['tpl_defaultname']; } set_magic_quotes_gpc($tplname); set_magic_quotes_gpc($description); if (!$idtpl) { $sql = "INSERT INTO " . $cms_db['tpl'] . " (name, description, idlay, idclient, author, created\n , lastmodified) VALUES ('{$tplname}', '{$description}', '{$idlay}', '{$client}'\n , '" . $auth->auth['uid'] . "', '" . time() . "', '" . time() . "')"; $db->query($sql); $idtpl = mysql_insert_id(); // Event fire_event('tpl_new', array('idtpl' => $idtpl, 'name' => $tplname)); } else { $sql = "UPDATE " . $cms_db['tpl'] . " SET\tname='{$tplname}', description='{$description}', idlay='{$idlay}',\n author='" . $auth->auth['uid'] . "', lastmodified='" . time() . "' WHERE idtpl='{$idtpl}'"; $db->query($sql); //rechte setzen if ($perm->have_perm('6', 'tpl', $idtpl)) { global $cms_gruppenids, $cms_gruppenrechte, $cms_gruppenrechtegeerbt, $cms_gruppenrechteueberschreiben; $perm->set_group_rights('tpl', $idtpl, $cms_gruppenids, $cms_gruppenrechte, $cms_gruppenrechtegeerbt, $cms_gruppenrechteueberschreiben, '', 0x35); } // Event fire_event('tpl_edit', array('idtpl' => $idtpl, 'name' => $tplname)); } // Array der alten Container erstellen $used_container = browse_template_for_module($idtpl, '0'); if (!is_array($used_container['id'])) { $used_container['id']['0'] = '0'; } // Array der neuen Container erstellen $list = browse_layout_for_containers($idlay); if (is_array($list['id'])) { foreach ($list['id'] as $i) { global ${'C' . $i . 'MOD_VAR'}, ${'c' . $i}, ${'cview' . $i}, ${'cedit' . $i}; if (${'c' . $i}) { $container['id'][] = $i; } if (${'C' . $i . 'MOD_VAR'}) { $cconfig[$i] = make_array_to_urlstring(${'C' . $i . 'MOD_VAR'}); } } } if (!is_array($container['id'])) { $container['id']['0'] = '0'; } foreach ($container['id'] as $value) { if ($value != '0') { // neue Container hinzufügen if (!in_array($value, $used_container['id'])) { $sql = "INSERT INTO {$cms_db['container']} (idtpl, container, idmod) VALUES ('{$idtpl}'\n , '{$value}', '" . ${'c' . $value} . "')"; $db->query($sql); $idcontainer = mysql_insert_id(); $sql = "INSERT INTO {$cms_db['container_conf']} (idcontainer, config, view, edit)\n VALUES ('{$idcontainer}', '{$cconfig[$value]}', '" . ${'cview' . $value} . "', '" . ${'cedit' . $value} . "')"; $db->query($sql); // Templatekopien suchen if (!$tpllist) { $sql = "SELECT idtplconf FROM " . $cms_db['tpl_conf'] . " WHERE idtpl='{$idtpl}'"; $db->query($sql); while ($db->next_record()) { $tpllist[] = $db->f('idtplconf'); } } if (is_array($tpllist)) { foreach ($tpllist as $idtplconf) { $sql = "INSERT INTO " . $cms_db['container_conf'] . " (idtplconf, idcontainer, config\n , view, edit) VALUES ('{$idtplconf}', '{$idcontainer}', '{$cconfig[$value]}'\n , '" . ${'cview' . $value} . "', '" . ${'cedit' . $value} . "')"; $db->query($sql); $change = 'true'; } } } // geänderte Container updaten if (${'c' . $value} == $used_container[$value]['idmod'] && ($cconfig[$value] != $used_container[$value]['config'] || ${'cview' . $value} != $used_container[$value]['view'] || ${'cedit' . $value} != $used_container[$value]['edit'])) { // Seiten / Ordnertemplates ändern if ($tpl_overwrite_all != '1') { $tpl_overwrite = " AND idtplconf='0'"; } else { $tpl_overwrite = ''; $change = 'true'; } $sql = "UPDATE\t" . $cms_db['container_conf'] . " SET config='" . $cconfig[$value] . "', view='" . ${'cview' . $value} . "'\n , edit='" . ${'cedit' . $value} . "' WHERE idcontainer='" . $used_container[$value]['idcontainer'] . "'{$tpl_overwrite}"; $db->query($sql); } // Modul wurde geändert if (${'c' . $value} != $used_container[$value]['idmod'] && $used_container[$value]['idmod']) { $sql = "UPDATE " . $cms_db['container'] . " SET idmod='" . ${'c' . $value} . "'\n WHERE idcontainer='" . $used_container[$value]['idcontainer'] . "'"; $db->query($sql); $sql = "UPDATE " . $cms_db['container_conf'] . " SET config='" . $cconfig[$value] . "', view='" . ${'cview' . $value} . "'\n , edit='" . ${'cedit' . $value} . "' WHERE idcontainer='" . $used_container[$value]['idcontainer'] . "'"; $db->query($sql); $change = 'true'; $empty_container[] = $value; } } } // alte Container löschen foreach ($used_container['id'] as $value) { if ($value != '0') { if (!in_array($value, $container['id'])) { $sql = "DELETE FROM {$cms_db['container']} WHERE idcontainer='" . $used_container[$value]['idcontainer'] . "'"; $db->query($sql); $sql = "DELETE FROM {$cms_db['container_conf']} WHERE idcontainer='" . $used_container[$value]['idcontainer'] . "'"; $db->query($sql); $change = 'true'; $empty_container[] = $value; } } } if ($change) { $list = get_idtplconf_by_using_type($idtpl, 'tpl'); // lösche alte 'content' Einträge if (is_array($empty_container)) { $list2 = get_idsidelang_by_idtplconf($list); $sql = "DELETE FROM {$cms_db['content']} WHERE idsidelang IN(" . implode(',', $list2) . ")\n AND container IN(" . implode(',', $empty_container) . ")"; $db->query($sql); $sql = "DELETE FROM {$cms_db['content_external']} WHERE idsidelang\n IN(" . implode(',', $list2) . ") AND container IN(" . implode(',', $empty_container) . ")"; $db->query($sql); unset($list2); } // Status der 'code' Tabelle ändern // jb_todo: change_code_status im dateimanager einführen $list = get_idcode_by_idtplconf($list); change_code_status($list, '1'); unset($list); } // Content aus Cache löschen sf_factoryCallMethod('UTILS', 'DbCache', null, null, 'flushByGroup', array('frontend', 'content')); }
function lay_edit_layout($idlay, $name, $description, $code, $doctype, $doctype_autoinsert, $idclient) { global $db, $client, $auth, $cms_db, $cfg_cms, $css, $js, $cms_lang, $cfg_client, $perm; // Eintrag in 'lay' Tabelle if ($name == '') { $name = $cms_lang['lay_defaultname']; } set_magic_quotes_gpc($name); set_magic_quotes_gpc($description); set_magic_quotes_gpc($code); // Layout existiert noch nicht - neu erzeugen if (!$idlay) { $sql = "INSERT INTO\n\t\t\t\t\t" . $cms_db['lay'] . "\n\t\t\t\t\t(name, description, deletable, code, doctype, doctype_autoinsert, idclient, author, created, lastmodified)\n\t\t\t\tVALUES\n\t\t\t\t\t('{$name}', '{$description}', '1', '{$code}', '{$doctype}', '{$doctype_autoinsert}', \n\t\t\t\t\t\t'{$idclient}', '" . $auth->auth['uid'] . "', '" . time() . "', '" . time() . "')"; $db->query($sql); // neue Layout-ID suchen $sql = "SELECT MAX(idlay) AS idlay FROM " . $cms_db['lay']; $db->query($sql); $db->next_record(); $idlay = $db->f('idlay'); // Event neues Layout fire_event('lay_new', array('idlay' => $idlay, 'name' => $name)); // Layout existiert - updaten } else { // hat sich das Layout geändert? $sql = "SELECT code FROM " . $cms_db['lay'] . " WHERE idlay='{$idlay}'"; $db->query($sql); $db->next_record(); $code_old = $db->f('code'); set_magic_quotes_gpc($code_old); $sql = "UPDATE " . $cms_db['lay'] . "\n\t\t\t\tSET\n\t\t\t\t\tname='{$name}', \n\t\t\t\t\tdescription='{$description}', \n\t\t\t\t\tcode='{$code}',\n\t\t\t\t\tdoctype='{$doctype}',\n\t\t\t\t\tdoctype_autoinsert='{$doctype_autoinsert}',\n\t\t\t\t\tauthor='" . $auth->auth['uid'] . "', lastmodified='" . time() . "'\n\t\t\t\tWHERE\n\t\t\t\t\tidlay='{$idlay}'"; $db->query($sql); $change = 'true'; //rechte setzen if ($perm->have_perm('6', 'lay', $idlay)) { global $cms_gruppenids, $cms_gruppenrechte, $cms_gruppenrechtegeerbt, $cms_gruppenrechteueberschreiben; $perm->set_group_rights('lay', $idlay, $cms_gruppenids, $cms_gruppenrechte, $cms_gruppenrechtegeerbt, $cms_gruppenrechteueberschreiben, '', 0xf5); } // Event fire_event('lay_edit', array('idlay' => $idlay, 'name' => $name)); } // welche CSS-Dateien werden benutzt? $sql = "SELECT B.idupl FROM {$cms_db['lay_upl']} A LEFT JOIN {$cms_db['upl']} B USING(idupl) LEFT JOIN {$cms_db['filetype']} C ON B.idfiletype=C.idfiletype WHERE idlay='{$idlay}' AND C.filetype='css'"; $db->query($sql); while ($db->next_record()) { $tmp_files['css'][] = $db->f('idupl'); } if (!is_array($tmp_files['css'])) { $tmp_files['css']['0'] = '0'; } if (!is_array($css)) { $css['0'] = '0'; } // benutzte CSS-Dateien in lay_upl schreiben foreach ($css as $value) { if (!in_array($value, $tmp_files['css'])) { if ($value != '0') { $sql = "INSERT INTO {$cms_db['lay_upl']} (idlay, idupl) VALUES ('{$idlay}', '{$value}')"; $db->query($sql); $change = 'true'; } } } // unbenutze CSS-Dateien aus lay_upl löschen foreach ($tmp_files['css'] as $value) { if (!in_array($value, $css)) { $sql = "DELETE FROM {$cms_db['lay_upl']} WHERE idupl='{$value}' AND idlay='{$idlay}'"; $db->query($sql); $change = 'true'; } } // welche JS-Dateien werden benutzt? $sql = "SELECT B.idupl FROM {$cms_db['lay_upl']} A LEFT JOIN {$cms_db['upl']} B USING(idupl) LEFT JOIN {$cms_db['filetype']} C ON B.idfiletype=C.idfiletype WHERE idlay='{$idlay}' AND C.filetype='js'"; $db->query($sql); while ($db->next_record()) { $tmp_files['js'][] = $db->f('idupl'); } if (!is_array($tmp_files['js'])) { $tmp_files['js']['0'] = '0'; } if (!is_array($js)) { $js['0'] = '0'; } // benutzte JS-Dateien in lay_upl schreiben foreach ($js as $value) { if (!in_array($value, $tmp_files['js'])) { if ($value != '0') { $sql = "INSERT INTO {$cms_db['lay_upl']} (idlay, idupl) VALUES ('{$idlay}', '{$value}')"; $db->query($sql); $change = 'true'; } } } // unbenutze JS-Dateien aus lay_upl löschen foreach ($tmp_files['js'] as $value) { if (!in_array($value, $js)) { $sql = "DELETE FROM {$cms_db['lay_upl']} WHERE idupl='{$value}' AND idlay='{$idlay}'"; $db->query($sql); $change = 'true'; } } if ($change) { // Status der 'code' Tabelle ändern $list = get_idtplconf_by_using_type($idlay, 'lay'); $list = get_idcode_by_idtplconf($list); change_code_status($list, '1'); unset($list); } return $idlay; }