* @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-04-30
* modified 2008-06-26, Dominik Ziegler, add security fix
*
* $Id$:
* }}
*
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
$properties = new PropertyCollection;
$db2 = new DB_ConLite;
if ($action == "client_new") {
$nextid = $db->nextid($cfg["tab"]["clients"]);
$idclient = $nextid;
$new = true;
}
if (!$perm->have_perm_area_action($area)) {
$notification->displayNotification("error", i18n("Permission denied"));
} else {
if (!isset($idclient)) {
$notification->displayNotification("error", i18n("No client ID passed"));
} else {
if (($action == "client_edit") && ($perm->have_perm_area_action($area, $action))) {
$sNewNotification = '';
if ($active != "1") {
$active = "0";
}
if ($new == true) {
$sLangNotification = i18n('Notice: In order to use this client, you must create a new language for it.');
$sTarget = $sess->url('frameset.php?area=lang');
$sJsLink = "parent.parent.location.href='" . $sTarget . "';
top.header.markActive(top.header.document.getElementById('sub_lang'));";
$sLangNotificationLink = sprintf(i18n('Please click %shere%s to create a new language.'), '', '');
$sNewNotification = '
' . $sLangNotification . '
' . $sLangNotificationLink;
if (substr($frontendpath, strlen($frontendpath) - 1) != "/") {
$frontendpath .= "/";
}
if (substr($htmlpath, strlen($htmlpath) - 1) != "/") {
$htmlpath .= "/";
}
$sql = "INSERT INTO
" . $cfg["tab"]["clients"] . "
SET
name = '" . Contenido_Security::escapeDB($clientname, $db) . "',
frontendpath = '" . Contenido_Security::escapeDB($frontendpath, $db) . "',
htmlpath = '" . Contenido_Security::escapeDB($htmlpath, $db) . "',
errsite_cat = '" . Contenido_Security::toInteger($errsite_cat) . "',
errsite_art = '" . Contenido_Security::toInteger($errsite_art) . "',
idclient = '" . Contenido_Security::toInteger($idclient) . "'";
$properties->setValue("idclient", $idclient, "backend", "clientimage", $clientlogo);
// Copy the client template to the real location
$destPath = $frontendpath;
$sourcePath = $cfg['path']['contenido'] . $cfg['path']['frontendtemplate'];
if ($copytemplate) {
if (!file_exists($destPath)) {
if (recursive_copy($sourcePath, $destPath)) {
$res = fopen($destPath . "config.php", "rb+");
$res2 = fopen($destPath . "config.php.new", "ab+");
if ($res && $res2) {
while (!feof($res)) {
$buffer = fgets($res, 4096);
$buffer = str_replace("!CLIENT!", $idclient, $buffer);
$buffer = str_replace("!PATH!", $cfg["path"]["contenido"], $buffer);
fwrite($res2, $buffer);
}
} else {
$notification->displayNotification("error", i18n("Couldn't write the file config.php."));
}
fclose($res);
fclose($res2);
unlink($destPath . "config.php");
rename($destPath . "config.php.new", $destPath . "config.php");
$message = sprintf(i18n("Succesfully copied client-template to %s."), $destPath);
$notification->displayNotification("info", $message);
} else {
$message = sprintf(i18n("Cannot create directory %s . The client was created, but you have to copy the frontend-template yourself"), $destPath);
$notification->displayNotification("warning", $message);
}
} else {
$message = sprintf(i18n("The directory %s already exists. The client was created, but you have to copy the frontend-template yourself"), $destPath);
$notification->displayNotification("warning", $message);
}
} else {
$message = sprintf(i18n("Client '%s' created."), $clientname);
$notification->displayNotification("info", $message);
}
rereadClients();
} else {
$pathwithoutslash = $frontendpath;
if (substr($frontendpath, strlen($frontendpath) - 1) != "/") {
$frontendpath .= "/";
}
if (substr($htmlpath, strlen($htmlpath) - 1) != "/") {
$htmlpath .= "/";
}
if (($oldpath != $frontendpath) && ($oldpath != $pathwithoutslash)) {
$notification->displayNotification("warning", i18n("You changed the client path. You might need to copy the frontend to the new location"));
}
$sql = "UPDATE
" . $cfg["tab"]["clients"] . "
SET
name = '" . Contenido_Security::escapeDB($clientname, $db) . "',
frontendpath = '" . Contenido_Security::escapeDB($frontendpath, $db) . "',
htmlpath = '" . Contenido_Security::escapeDB($htmlpath, $db) . "',
errsite_cat = '" . Contenido_Security::toInteger($errsite_cat) . "',
errsite_art = '" . Contenido_Security::toInteger($errsite_art) . "'
WHERE
idclient = '" . Contenido_Security::toInteger($idclient) . "'";
}
$db->query($sql);
$new = false;
rereadClients();
$properties->setValue("idclient", $idclient, "backend", "clientimage", $clientlogo);
/* Clear the con_code table */
$sql = "DELETE FROM " . $cfg["tab"]["code"] . " WHERE idclient = '" . Contenido_Security::toInteger($idclient) . "'";
$db->query($sql);
$notification->displayNotification("info", i18n("Changes saved") . $sNewNotification);
$cApiClient = new cApiClient;
$cApiClient->loadByPrimaryKey($idclient);
if (isset($_REQUEST["generate_xhtml"])) {
switch ($_REQUEST["generate_xhtml"]) {
case "html":
$cApiClient->setProperty("generator", "xhtml", "false");
$cApiClient->setProperty("generator", "html5", "false");
break;
case "xhtml":
$cApiClient->setProperty("generator", "xhtml", "true");
$cApiClient->setProperty("generator", "html5", "false");
break;
case "html5":
$cApiClient->setProperty("generator", "xhtml", "false");
$cApiClient->setProperty("generator", "html5", "true");
break;
default: // do nothing
break;
}
}
}
$tpl->reset();
$sql = "SELECT
idclient, name, frontendpath, htmlpath, errsite_cat, errsite_art
FROM
" . $cfg["tab"]["clients"] . "
WHERE
idclient = '" . Contenido_Security::toInteger($idclient) . "'";
$db->query($sql);
$db->next_record();
$form = '