setForm(); // foreach ($returned_values as $column => $value) { global $default; if ($value[1] == "TEXT") { $this->addElement($value[1],$value[2],$value[0],$value[4]); $error = $this->errorForm($value[2]); $this->addRule($value[2], $error, $value[3], null); } elseif ($value[1] == "SELECT") { if ($value[2] == "secgroup") { $select_array = $this->groups(NULL); } $this->addElement($value[1],$value[2],$value[0],$select_array,$value[4]); $error = $this->errorForm($value[2]); $this->addRule($value[2], $error, $value[3]); } elseif ($value[1] == "PASSWORD") { $this->addElement($value[1],$value[2],$value[0],$value[4]); $error = $this->errorForm($value[2]); $this->addRule($value[2], $error, $value[3], null); } elseif ($value[1] == "TEXTAREA") { $this->addElement($value[1],$value[2],$value[0],$value[4]); $error = $this->errorForm($value[2]); $this->addRule($value[2], $error, $value[3]); } } $pass_error = $this->errorForm("password_confirm"); $this->addRule(array('password','password_confirm'), $pass_error, 'compare'); $this->addElement("submit", "checkButton", "Submit"); } function setForm() { /* function: setForm purpose: create the form fields you want. returns: array of form fields */ global $form_strings; // array offset: 0 1 2 3 4 5 $fields = array("USERNAME" => array($form_strings['LBL_USERNAME'],"TEXT","username","required",array("size" => "25"),"General Settings"), "FIRSTNAME" => array($form_strings['LBL_FIRSTNAME'],"TEXT","first_name","required",array("size" => "25"),"General Settings"), "LASTNAME" => array($form_strings["LBL_LASTNAME"],"TEXT","last_name","required",array("size" => "40","maxlength" => "200"),"General Settings"), "PASSWORD" => array($form_strings["LBL_PASSWORD"],"TEXT","password","required",array("size" =>"15"),"General Settings"), "PASSWORD_CONFIRM" => array($form_strings["LBL_PASSWORD_CONFIRM"],"TEXT","password_confirm","required",array("size" =>"15"),"General Settings"), "SECGROUP" => array($form_strings["LBL_SECGROUP"],"SELECT","secgroup","required",array("size" =>"1"),"General Settings"), "EMAIL" => array($form_strings["LBL_EMAIL"],"TEXT","email","required",array("size" =>"25"),"General Settings") ); return $fields; } function errorForm($val) { /** function: errorForm * purpose: create the error return values from the form fields you want. * returns: array of form fields with error codes */ global $error_strings; //form_return ($type,$size,$name,$vals) $fields = array("USERNAME" => array($error_strings['ERR_USERNAME'], "username"), "FIRSTNAME" => array($error_strings['ERR_IMAGE_NAME'],"image_name"), "LASTNAME" => array($error_strings["ERR_IMAGE_PATH"],"image_path"), "PASSWORD" => array($error_strings["ERR_PASSWORD"],"password"), "PASSWORD_CONFIRM" => array($error_strings["ERR_PASSWORD_CONFIRM"],"password_confirm"), "SECGROUP" => array($error_strings["ERR_SECGROUP"],"group"), "EMAIL" => array($error_strings["ERR_EMAIL"],"email") ); foreach ($fields as $error_col => $error_val) { if ($error_val[1] == $val) { // we just return the error text associated with the form field name ($val) and nothing else return $error_val[0]; } } } function groups() { /* function: group purpose: to return security groups - only "admin" and "user" fixed groups are applicable; a more intelligent, scalable permissions/ACL system may be forthcoming. returns: security groups */ $groups = array("" => "-->Pick a security group", "admin" => "admin", "user" => "user", ); return $groups; } function addDB() { /* function: addDB() purpose: adds this Windows image location to the database */ $con =& MDB2::factory(unserialize(DSN)); if (PEAR::isError($con)) { die($con->getMessage()); } else { $image_exists = FastDeploy::queryImage($_POST['imageid']); if ($image_exists) { // $image_add = $con->query("UPDATE windows_images SET image_name='". $_POST['image_name'] ."',image_path='". $_POST['image_path'] ."',os_version='". $_POST['os_version'] ."',os_subversion='". $_POST['os_subversion'] ."',arch='". $_POST['arch'] ."' WHERE imageid='". $_POST['imageid'] ."'"); } else { $image_add = $con->query("INSERT INTO windows_images (image_name,image_path,os_version,os_subversion,arch) VALUES ('". $_POST['image_name'] ."','". $_POST['image_path'] ."','". $_POST['os_version'] ."','". $_POST['os_subversion'] ."','". $_POST['arch'] ."')"); } } } } $form = new UserAdmin(); $template =& new Smarty; $template->compile_dir = '/tmp'; $template->left_delimiter = '{{'; $template->right_delimiter = '}}'; if ($_GET['op'] == "edit") { $set_edit = FastDeploy::queryUser($_GET['uid']); if ($set_edit) { $form->setDefaults($set_edit); // populate the form with existing data - HTML_Quickform makes this way easy } else { $form->setDefaults($_GET); } } if ($_GET['op'] == "delete") { } if ($form->validate()) { $form->freeze(); $form->addDB(); // add the image to the database... foreach ($_POST as $name => $val) { $template->assign($name,$val); } $template->display("images.html"); } else { // display the default form // Create the Smarty renderer object that HTML_Quickform will shuffle its output to $renderer =& new HTML_QuickForm_Renderer_ArraySmarty($template); $renderer->setRequiredTemplate( '{{if $error}} {{$label}} {{else}} {{$label}} {{if $required}} * {{/if}} {{/if}}' ); $rn = '
* Denotes required field
'; $renderer->setErrorTemplate( '{{if $error}} {{$error}}
{{/if}} {{$html}}' ); $form->setRequiredNote($rn); // build the HTML for the form $form->accept($renderer); // assign array with form data $template->assign('form_data', $renderer->toArray()); // parse and display the template $template->display("useradmin.html"); } ?>