Update of /cvsroot/phpslash/phpslash-dev/include/modules/variable
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13201/phpslash-dev/include/modules/variable
Added Files:
Variable.class admin.php
Log Message:
removed classes that already had been moved to module directories. moved Infolog and slashAuth to module directories.
--- NEW FILE: Variable.class ---
<?php
/*
* Class: Variable
*
* Layer: All
* Desc.:
*
* NOTES/TO-DO: get rid of the global's
*
*/
class Variable {
var $variable_templ;
var $var_array;
var $db;
var $psl;
/*
* CONSTRUCTORS
*/
function Variable () {
global $_PSL, $message;
$this->var_array['rootdir'] = $_PSL['rooturl'];
$this->var_array['basedir'] = $_PSL['basedir'];
$this->psl = $_PSL;
$this->db = pslNew("slashDB");
$this->message = '';
/* Templates */
$this->variable_templ = pslNew("slashTemplate",$this->psl['templatedir']);
$this->variable_templ->debug = 0;
$this->variable_templ->set_file(array(
listvariable => "variableList.tpl",
newvariable => "variableNew.tpl"
));
}
/*
* METHODS
*/
function getvar($variable_name, $mode="")
{
if (isset($this->var_array[$variable_name])) {
return $this->var_array[$variable_name]; # we have it - return it.
} else {
#get var from db and store in cache ($this->var_array)
$query = "SELECT variable_name,
value
FROM psl_variable
WHERE variable_name='$variable_name'";
$this->db->query($query);
if ($this->db->next_record()) {
$this->var_array[$variable_name] = $this->db->Record[value];
} else {
if( $mode != "quiet") {
$this->message = "<BR><BR><B>VARIABLE.CLASS::GETVAR: I don't have a \$$variable_name variable!!</B><BR><BR>\n";
}
return 0;
}
}
return $this->var_array[$variable_name];
}
function setvar($name,$val) {
if ( ($name == "") || ($val == "") ) {
return false;
}
$query = "UPDATE psl_variable
SET value='$val'
WHERE variable_name='$name'";
if ($this->db->query($query)) {
return true;
} else {
return false;
};
}
/*
* Just prints the form with the list of existing variables
* Used only by admin
*/
function listVariable() {
$q = "SELECT *
FROM psl_variable
ORDER BY variable_name";
$this->db->query($q);
$this->variable_templ->set_var('TITLEBAR',getTitlebar("100%","Change existing Variable"));
$this->variable_templ->set_block("listvariable","row","rows");
while ($this->db->next_record()) {
$variable_id = $this->db->Record[variable_id];
$admin = "<A HREF=$this->psl['phpself']?submit=edit&variable_id=$variable_id>(Edit)</A>";
$admin .= "<A HREF=$this->psl['phpself']?submit=delete&variable_id=$variable_id>(Delete)</A>";
$this->variable_templ->set_var(array(
ACTION_URL => $this->psl['phpself'],
VARIABLE_ID => $variable_id,
VARIABLE_NAME => $this->db->Record[variable_name],
VARIABLE_DESC => $this->db->Record[description],
VARIABLE_VALUE => $this->db->Record[value],
ADMIN => $admin
));
$this->variable_templ->parse("rows","row",true);
};
return $this->variable_templ->parse(OUT,array("listvariable"));
// $this->variable_templ->p(OUT);
}
/*
* Saves the variable in the $ary array to the DB
* Obligatory fields: variable_name, description, value
* Optional fields: variable_id (only if this variable is already in the DB),
* Returns true if sucessful (variable added or updated), false on error
* Used only by admin
*/
function saveVariable($ary) {
/* we need to check for the stuff to add in the DB before we actually
* add anything. And yes, I know it looks like I just passed my
* "Intro to C++ Programming" class. --ajay
*/
/* We don't test for variable_id because no variable_id means, that
this is a new variable. We also don't test for the "value" because
an empty value is a valid one. */
if ($ary[variable_name] == "") {
$this->message = "There is no variable_name in Variable.class::saveVariable";
return false;
}
if ($ary[description] == "") {
$this->messge = "There is no description in Variable.class::saveVariable";
return false;
}
/* addslashes for the (') AND str_replace for the (") */
$ary[description] = clean($ary["description"]);
$ary[variable_name] = clean($ary["variable_name"]);
$ary[variable_name] = clean($ary["variable_name"]);
/* if a record exists, then we update, else we insert a new variable! */
if (isset($ary[variable_id])) {
$this->db->query("SELECT variable_id
FROM psl_variable
WHERE variable_id = '$ary[variable_id]'");
if ($this->db->next_record()) {
$q = "UPDATE psl_variable
SET variable_name = '$ary[variable_name]',
description = '$ary[description]',
value = '$ary[value]',
variable_group = '$ary[group]'
WHERE variable_id = '$ary[variable_id]'";
}
$this->message = "Variable updated";
} else {
$ary[variable_id] = generateID("psl_variable_seq");
$q = "INSERT INTO psl_variable
(variable_id,
variable_name,
description,
value,
variable_group)
VALUES ('$ary[variable_id]',
'$ary[variable_name]',
'$ary[description]',
'$ary[value]',
'$ary[group]')";
$this->message = "Variable saved";
}
# echo "<BR><B>QUERY: $q</B><BR>\n";
$this->db->query($q);
return true;
}
/* Given the variable_id, it deletes that from the variable table. The
* psl_variable_lut and psl_variable_submission_lut table must be cleaned
* first by updating all the stories to point to different variables. It
* will also check and make sure there are NO stories/submissions
* associated with this variable before deleting it. Returns true if
* variable is deleted, false if not.
*/
function deleteVariable($variable_id) {
if (!$variable_id) {
return false;
}
$q = "DELETE
FROM psl_variable
WHERE variable_id = '$variable_id'";
if ($this->db->query($q)) {
return true;
} else {
return false;
}
}
/*
* Just prints out the "form" and points the user to the "save" method
* Used only by admin
*/
function newVariable() {
$this->variable_templ->set_var(array(
'TITLEBAR' => getTitlebar("100%","Add a new Variable"),
ACTION_URL => $this->psl['phpself']
));
return $this->variable_templ->parse(OUT,array("newvariable"));
// $this->variable_templ->p(OUT);
}
} /* end of Variable.class */
?>
--- NEW FILE: admin.php ---
<?php
// $Id: admin.php,v 1.1 2004/09/15 23:31:47 joestewart Exp $
global $_PSL, $sess, $auth, $perm;
# header title
$pagetitle = pslgetText("Administration");
#Defines The META TAG Page Type
$xsiteobject = pslgetText("Administration");
/*****************************
START OF PAGE
*****************************/
$auth->login_if(!$perm->have_perm('variableList'));
/* DEBUG */
// debug( "HTTP_POST_VARS" , $HTTP_POST_VARS);
// debug( "HTTP_GET_VARS" , $HTTP_GET_VARS);
// debug( "variable_name", $variable_name );
/* DEBUG */
AddClassRequirement("topic",$_PSL['moduledir'] ."/variable/Variable.class");
$variable = pslNew("Variable");
$content = '';
if(!empty($HTTP_POST_VARS['submit'])) {
$submit = clean($HTTP_POST_VARS['submit']);
$variable_ary = clean($HTTP_POST_VARS['variable_ary']);
$variable_name = clean($HTTP_POST_VARS['variable_name']);
$variable_id = clean($HTTP_POST_VARS['variable_id']);
$description = clean($HTTP_POST_VARS['description']);
$variable_value = clean($HTTP_POST_VARS['variable_value']);
$variable_group = clean($HTTP_POST_VARS['variable_group']);
} elseif (!empty($HTTP_GET_VARS['submit'])) {
$submit = clean($HTTP_GET_VARS['submit']);
} else {
$submit = '';
}
if ($perm->have_perm("variableList")) {
switch ($submit) {
case "delete":
if($perm->have_perm("variableDelete")) {
while ( list( $key, $val ) = each( $variable_ary ) ) {
$success = $variable->deleteVariable($variable_ary[$key]);
}
}
break;
case "new":
if($perm->have_perm("variableSave")) {
$success = $variable->saveVariable(clean($HTTP_POST_VARS));
}
break;
case "update":
if($perm->have_perm("variableEdit")) {
reset ($variable_id);
while ( list( $key, $val ) = each( $variable_id ) ) {
$ary["variable_id"] = $variable_id[$key];
$ary["variable_name"] = $variable_name[$key];
$ary["description"] = $description[$key];
$ary["value"] = $variable_value[$key];
$ary["variable_group"] = $variable_group[$key];
if ($variable->saveVariable($ary)) {
$content .= "<em>$variable_name[$key]</em> has been updated<BR>\n";
} else {
$content .= "<em>$variable_name[$key]</em> has <strong>not</strong> been updated<BR>\n";
}
}
}
break;
default:
break;
}
if($perm->have_perm("variableNew")) {
$content .= $variable->newVariable();
}
if($perm->have_perm("variableList")) {
$content .= $variable->listVariable();
}
} else {
$content = getTitlebar("100%","Error! Invalid Privileges");
$content .= "Sorry. You do not have the necessary privilege to view this page.";
}
return $content;
?>
|