function categoryForm()
{
    //put contents here
    $process = new ProcessForm();
    $validate = $process::validate();
    $postdata = new Table("pagecategory");
    if ($GLOBALS["action"] == "editpgcate") {
        $postdata::$id = "Id=" . $GLOBALS["id"];
        $editcate = $postdata::findRow($postdata::$id);
        $category = $editcate->Category;
        $visible = $editcate->Visible;
        $position = $editcate->Position;
    } else {
        $category = "";
        $visible = "";
        $position = "";
    }
    if ($process->submitForm()) {
        /*@setting validation rules*/
        $required = array("category");
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_requiredFields($required));
        $check_invalidchars = array("category");
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_invalidChars($check_invalidchars));
        $requiredlen = array("category" => 30);
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_FieldLength($requiredlen));
        $selectedindex = array("position" => "--Select Menu Position--");
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_selectField($selectedindex));
        $process->message("category has been successfully submmited.");
        if ($process->successflag) {
            //echo "success happened and all fields are sent to database, Thank you ! :)";//
            $postdata::$tablefields = array("Category" => $_POST["category"], "Position" => $_POST["position"], "Visible" => $_POST["visible"]);
            $postdata->save();
        }
    }
    $form = new Form("sitenavform", $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'], "post", "enctype=\"application/x-www-form-urlencoded\"\n");
    //Company
    $form->startForm();
    $form->setFormField("", $form->addFormInfo("<p>" . GenerateUrl::buildLink(".", "dashboard.php", "&laquo;Back to Sammary Page", "action=view,target=managesite") . "</p>" . "<h2>Use this form to add new page category.</h2><p>Required Fields are labelled with asterics (*)<hr/>"));
    //Category
    $form->setFormField($form->inputLabel("category", "*Category Name"), $form->inputField("text", "category", $process->post("category", $category)), $validate->displayErrorField($process->errorinfo, "category"));
    //Position
    $cateposition = function () {
        $getposition = new Table("sitemenu");
        $position_options = $getposition::findAllRecords("ORDER BY Id ASC");
        foreach ($position_options as $opt) {
            $options[0] = "--Select Menu Position--";
            $options[$opt->Position] = $opt->Nav_name;
        }
        return $options;
    };
    $form->setFormField($form->inputLabel("position", "*Menu Position"), $form->selectOptions("position", $cateposition(), $process->post("position", $position)), $validate->displayErrorField($process->errorinfo, "position"));
    //Radio for Visible//
    $form->setFormField($form->inputLabel("visible", "Menu Visibility"), $form->radioButton("Yes", "visible", "Y", $process->post("visible", $visible) == "Y" ? true : false) . $form->radioButton("No", "visible", "N", $process->post("visible", $visible) == "N" ? true : false));
    //Submit Form//
    $form->setFormField(null, $form->inputField("submit", "send", "Save"));
    $form->endForm();
    return $form->DisplayFields($GLOBALS["form_labling"], $process->message);
}
function pageform()
{
    global $session;
    $process = new ProcessForm();
    $validate = $process::validate();
    $postdata = new Page("pages");
    $user = new User("users");
    $uid = $user::findRow("Id={$session->userid}");
    //change this to login session id when login is activated
    $id = $postdata::$id = isset($GLOBALS["id"]) ? "Id=" . $GLOBALS["id"] : null;
    //id recieved form querystring
    if ($GLOBALS["action"] == "editpage") {
        $edit = $postdata::findRow($id);
        //
        $title = $edit->Title;
        $category = $edit->Position;
        $source = $edit->Source;
        $pgcontent = $edit->Content;
        $published = $edit->Published;
        $featured = $edit->Featured;
        $authorid = $uid->Id;
        //image to upload
        $pgimage = "";
        $imgcaption = "";
    } else {
        $title = "";
        $category = "";
        $source = "";
        $pgcontent = "";
        $published = "";
        $featured = "";
        $authorid = $uid->Id;
        //image to upload
        $pgimage = "";
        $imgcaption = "";
        //debug($authorid);
    }
    //Process Page Form
    //Process Image Uploads here
    $upload_path = "../";
    $upload = new UploadFiles($upload_path . PAGEIMG_DIR, $upload_path . TEMP_DIR);
    if ($process->submitForm()) {
        /*@setting validation rules*/
        $upload->Mimetype = array('image/pjpeg' => "jpeg", 'image/jpeg' => "jpeg", 'image/png' => "png", 'image/gif' => "gif");
        $required = array("title", "page_content", "source");
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_requiredFields($required));
        $check_invalidchars = array("title", "source");
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_invalidChars($check_invalidchars));
        $requiredlen = array("title" => 100);
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_FieldLength($requiredlen));
        $selectedindex = array("category" => "--Select Category--");
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_selectField($selectedindex));
        if ($id == null) {
            $getrow = $postdata::fieldExists("Title={$_POST["title"]}");
            if ($getrow) {
                $process->errorinfo["title"] = $_POST["title"] . " already exist";
            }
        }
        /* upload info on validation ,//Sucess*/
        $massage = $process->message("Page has been successfully submmited.");
        if ($process->successflag) {
            //put database table here
            $postdata::$tablefields = array("Title" => $_POST["title"], "Content" => $_POST["page_content"], "Source" => $_POST["source"], "Postedby" => $_POST["authorid"], "Position" => $_POST["category"], "Published" => $_POST["publish"], "Featured" => $_POST["feature"]);
            /*saved to database*/
            $postdata->save();
            //echo "new recored was added with id=".$postdata->lastInsertedId();
            //echo "<br> success happened and all fields are sent to database, Thank you ! :)";
            /*uploads info*/
            $upload->uploadFile("uploadimg");
            //upolads an image
            if ($upload->Upload_status == true) {
                $postimg = new Image("pageimgs");
                $pageid = $id != null ? $id : $postdata->lastInsertedId();
                $postimg::$tablefields = array("Imgname" => $upload->Newfilename, "Width" => $upload->Width, "Height" => $upload->Height, "Imgcaption" => $_POST["imgcaption"], "Mimetype" => $upload->Filetype, "Extention" => $upload->File_ext, "Pageid" => $pageid);
                //check and delete old image record in pageimg table
                $pid = $postimg->findRow("Pageid=" . $pageid);
                if ($pid != null) {
                    //if(file_exists($upload_path.PAGEIMG_DIR.$pid->Imgname.".".$pid->Extention)){
                    $upload->deleteFile($upload_path . PAGEIMG_DIR . $pid->Imgname . "." . $pid->Extention);
                    $upload->deleteFile($upload_path . PAGEIMG_DIR . "thumbnails/" . $pid->Imgname . "." . $pid->Extention);
                }
                // }
                $postimg->save();
            }
        }
        //upload image
    }
    $form = new Form("Pageform", filter_var($_SERVER['PHP_SELF']) . "?" . filter_var($_SERVER['QUERY_STRING']), "post", "enctype=\"multipart/form-data\"\n");
    //Company;
    $form->startForm();
    $form->setFormField("", $form->addFormInfo("<h2>Use this form add new Page..</h2><p>Required Fields are labelled with asterics (*)</p><hr/>"));
    //Page Title
    $form->setFormField($form->inputLabel("title", "*Title"), $form->inputField("text", "title", $process->post("title", $title)), $validate->displayErrorField($process->errorinfo, "title"));
    //Category
    $pgcategory = function () {
        $category = new GetTableRecord("pagecategory");
        $category_options = $category::findAllRecords();
        $options[] = "--Select Category--";
        foreach ($category_options as $opt) {
            $options[$opt->Position] = $opt->Category;
        }
        return $options;
    };
    $form->setFormField($form->inputLabel("category", "*Category"), $form->selectOptions("category", $pgcategory(), $process->post("category", $category)), $validate->displayErrorField($process->errorinfo, "category"));
    //Page Source
    $form->setFormField($form->inputLabel("source", "*Source"), $form->inputField("text", "source", $process->post("source", $source)), $validate->displayErrorField($process->errorinfo, "source"));
    // Page Content
    $form->setFormField($form->inputLabel("page_content", "*Content"), $form->textAreaField("page_content", $process->post("page_content", $pgcontent), "10", "50", "class=\"ckeditor\""), $validate->displayErrorField($process->errorinfo, "page_content"));
    //Upload Image
    $form->setFormField($form->inputLabel("uploadimg", "Upload Image"), $form->uploadField("uploadimg[]", "uploadimg") . "<br>" . $form->textAreaField("imgcaption", $process->post("imgcaption", $imgcaption), "1", "45", 'placeholder="Image Caption"') . $form->inputField("hidden", "MAX_FILE_SIZE", "40000000"), $validate->displayErrorField($process->errorinfo, "uploadimg"));
    //Radio for Visible/
    $form->setFormField($form->inputLabel("publish", "Publish"), $form->radioButton("Yes", "publish", "Y", $process->post("publish", $published) == "Y" ? true : false) . $form->radioButton("No", "publish", "N", $process->post("publish", $published) == "N" ? true : false));
    //Featured Page
    $form->setFormField($form->inputLabel("feature", "Feature"), $form->radioButton("Yes", "feature", "Y", $process->post("feature", $featured) == "Y" ? true : false) . $form->radioButton("No", "feature", "N", $process->post("feature", $featured) == "N" ? true : false));
    //Submit Form
    $form->setFormField(null, $form->inputField("hidden", "authorid", $process->post("authorid", $authorid)) . $form->inputField("submit", "send", "Save"));
    $form->endForm();
    return $form->DisplayFields($GLOBALS["form_labling"], $process->message);
}
Example #3
0
echo HTML::para(HTML::link(_("Install dump from file"), '../install/index.php') . ' | ' . HTML::link(_("Optimize Database"), '../admin/dump_optimize_db.php'));
if ($numTables < 1) {
    // @todo message
    require_once "../layout/footer.php";
    exit;
}
echo HTML::insertScript('dump_functions.js');
echo HTML::start('form', array('method' => 'post', 'action' => './dump_process.php'));
$i = 0;
$table = null;
while ($i < $numTables) {
    DUMP_MYSQL_INT_VERSION >= 32303 ? $table[$tables[$i]['Name']] = $tables[$i]['Name'] : ($table[$tables[$i]] = $tables[$i]);
    $i++;
}
$fieldArray = array(Form::select("table_select", $table, null, array('size' => 15)));
unset($table);
$fieldFoot = array(HTML::link(_("Select all"), '#', null, array('id' => 'select_all')) . ' / ' . HTML::link(_("Unselect all"), '#', null, array('id' => 'unselect_all')));
echo Form::fieldset(_("View dump of database"), $fieldArray, $fieldFoot, array('id' => 'dump_tables'));
$fieldArray = null;
$fieldArray[] = Form::radioButton("what", "data", array('id' => 'radio_dump_data', 'checked' => true)) . Form::label("radio_dump_data", _("Structure and data"));
$fieldArray[] = Form::radioButton("what", "structure", array('id' => 'radio_dump_structure')) . Form::label("radio_dump_structure", _("Structure only"));
$fieldArray[] = Form::radioButton("what", "dataonly", array('id' => 'radio_dump_dataonly')) . Form::label("radio_dump_dataonly", _("Data only"));
$fieldArray[] = Form::radioButton("what", "xml", array('id' => 'radio_dump_xml')) . Form::label("radio_dump_xml", _("Export to XML format"));
$fieldArray[] = Form::radioButton("what", "excel", array('id' => 'radio_dump_csv')) . Form::label("radio_dump_csv", _("Export to CSV format (data only)"));
echo Form::fieldset(_("Options"), $fieldArray, null, array('id' => 'dump_options'));
$fieldArray = array(Form::checkBox("drop", "yes") . Form::label("drop", _("Add 'DROP TABLE'")), Form::checkBox("show_columns", "yes") . Form::label("show_columns", _("Complete 'INSERTs'")), Form::checkBox("extended_inserts", "yes") . Form::label("extended_inserts", _("Extended 'INSERTs'")), Form::checkBox("use_backquotes", "yes") . Form::label("use_backquotes", _("Enclose table and field names with backquotes")), Form::checkBox("add_delete", "yes") . Form::label("add_delete", _("Add 'DELETE * FROM __table__'")), Form::checkBox("use_dbname", "yes") . Form::label("use_dbname", _("Add 'USE __dbname__'")), Form::checkBox("create_db", "yes") . Form::label("create_db", _("Add 'CREATE DATABASE __dbname__'")), Form::checkBox("as_file", "sendit") . Form::label("as_file", _("Save as file")));
echo Form::fieldset(_("Extended options"), $fieldArray, null, array('id' => 'dump_extended'));
echo HTML::para(Form::button("dump", _("Submit")) . Form::generateToken(), array('class' => 'center'));
echo HTML::end('form');
echo Msg::hint(_("Note: Some check options are exclusive. Be carefully!"));
require_once "../layout/footer.php";
function userProfileForm($setuserlevel = false)
{
    //put contents here
    include_once "../includes/admin_init.php";
    $process = new ProcessForm();
    $validate = $process::validate();
    $postdata = new User("users");
    $id = $postdata::$id = isset($GLOBALS["id"]) ? "Id=" . $GLOBALS["id"] : null;
    //id recieved form querystring
    if ($GLOBALS["action"] == "editregister") {
        $edit = $postdata::findRow($id);
        //
        $firstname = $edit->Firstname;
        $lastname = $edit->Lastname;
        $gender = $edit->Gender;
        $username = $edit->Username;
        $email = $edit->Email;
    } elseif ($GLOBALS["action"] == "edituser") {
        $edit = $postdata::findRow($id);
        //
        $firstname = $edit->Firstname;
        $lastname = $edit->Lastname;
        $gender = $edit->Gender;
        $username = $edit->Username;
        $email = $edit->Email;
        $status = $edit->Status;
        $ulevel = $edit->Authlevel;
    } else {
        $firstname = "";
        $lastname = "";
        $gender = "";
        $username = "";
        $password = "";
        $email = "";
        $status = "";
        $ulevel = "";
    }
    if ($process->submitForm()) {
        /*@setting validation rules*/
        $required = array("firstname", "lastname", "gender", "username", "email_address");
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_requiredFields($required));
        $check_invalidchars = array("firstname", "lastname", "username");
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_invalidChars($check_invalidchars));
        $requiredlen = array("firstname" => 50, "lastname" => 50, "username" => 50);
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_FieldLength($requiredlen));
        $selectedindex = $setuserlevel == true ? array("gender" => "--Select Gender--", "ulevel" => "--Select User Level--") : array("gender" => "--Select Gender--");
        $process->errorinfo = array_merge($process->errorinfo, $validate->check_selectField($selectedindex));
        if ($_POST && ($GLOBALS["action"] != "editregister" && $GLOBALS["action"] != "edituser")) {
            $getrow = $postdata::fieldExists("Username={$_POST["username"]}");
            if ($getrow != null) {
                $process->errorinfo["username"] = $_POST["username"] . " already a users, try anther username please";
            }
        }
        if ($GLOBALS["action"] == "adduser") {
            array_push($required, "password");
            $process->errorinfo = array_merge($process->errorinfo, $validate->check_requiredFields($required));
            $process->errorinfo = array_merge($process->errorinfo, $validate->check_PasswordFields("password", "cpassword"));
        }
        //Sucess
        //$process->message("Hey successfully submmited the form");
        //echo "success happened and all fields are sent to database, Thank you ! :)";
        $linkto = GenerateUrl::buildLink("../auth", ".", "Login");
        switch ($GLOBALS["action"]) {
            case "editregister":
                $process->message("Hey, {$firstname} have successfully edited your profile.");
                if ($process->successflag) {
                    $postdata::$tablefields = array("Firstname" => $_POST["firstname"], "Lastname" => $_POST["lastname"], "Gender" => $_POST["gender"], "Username" => $_POST["username"], "Email" => $_POST["email_address"]);
                    $postdata->save();
                }
                break;
            case "edituser":
                $process->message("You have successfully updated {$firstname}'s account");
                if ($process->successflag) {
                    $postdata::$tablefields = array("Firstname" => $_POST["firstname"], "Lastname" => $_POST["lastname"], "Gender" => $_POST["gender"], "Username" => $_POST["username"], "Email" => $_POST["email_address"], "Status" => $_POST["status"], "Authlevel" => $_POST["ulevel"]);
                    $postdata->save();
                }
                break;
            case "adduser":
                $process->message("You have successfully registered {$firstname}, please you can {$linkto} now.");
                if ($process->successflag) {
                    $postdata::$tablefields = array("Firstname" => $_POST["firstname"], "Lastname" => $_POST["lastname"], "Gender" => $_POST["gender"], "Username" => $_POST["username"], "Email" => $_POST["email_address"], "Password" => md5($_POST["password"]), "Status" => $_POST["status"], "Authlevel" => $_POST["ulevel"]);
                    $postdata->save();
                }
                break;
            default:
                //$linkto = GenerateUrl::buildLink("../auth",".","Login");
                // if($process->successflag){
                // $process->message("Your registeration was successfully, please you can {$linkto} now.");
                // $postdata::$tablefields = array(
                // "Firstname"     => $_POST["firstname"],
                // "Lastname"      => $_POST["lastname"],
                // "Gender"        => $_POST["gender"],
                // "Username"      => $_POST["username"],
                // "Email"         => $_POST["email_address"],
                // "Password"      => md5($_POST["password"]));
                // $postdata->save();
                // }
                break;
        }
    }
    $querystr = isset($_SERVER['QUERY_STRING']) ? "?" . $_SERVER['QUERY_STRING'] : null;
    $form = new Form("Register", $_SERVER['PHP_SELF'] . $querystr, "post", "enctype=\"application/x-www-form-urlencoded\"\n");
    $form->startForm();
    //form heading
    if ($GLOBALS["action"] == "editregister") {
        $form->setFormField(null, $form->addFormInfo("<h2>Edit your profile ..</h2>"));
    } elseif ($GLOBALS["action"] == "edituser") {
        $form->setFormField(null, $form->addFormInfo("<h2>Edit User Account</h2>"));
    } else {
        $form->setFormField(null, $form->addFormInfo("<h2>Use this form to add register new users..</h2>"));
    }
    //FIrstname
    $form->setFormField($form->inputLabel("firstname", "Firstname"), $form->inputField("text", "firstname", $process->post("firstname", $firstname)), $validate->displayErrorField($process->errorinfo, "firstname"));
    //Lastname
    $form->setFormField($form->inputLabel("lastname", "Lastname"), $form->inputField("text", "lastname", $process->post("lastname", $lastname)), $validate->displayErrorField($process->errorinfo, "lastname"));
    //gender
    $gender_options = array("--Select Gender--", "M" => "Male", "F" => "Female");
    $form->setFormField($form->inputLabel("gender", "Gender"), $form->selectOptions("gender", $gender_options, $process->post("gender", $gender)), $validate->displayErrorField($process->errorinfo, "gender"));
    //Username
    $form->setFormField($form->inputLabel("username", "Username"), $form->inputField("text", "username", $process->post("username", $username)), $validate->displayErrorField($process->errorinfo, "username"));
    //Email Address
    $form->setFormField($form->inputLabel("email", "Email"), $form->inputField("email", "email_address", $process->post("email_address", $email)), $validate->displayErrorField($process->errorinfo, "email_address"));
    //checks userlevel
    if ($setuserlevel == true) {
        //Userlevel
        $level_options = array("--Select User Level--", ADMIN => "Admin", MODERATOR => "Moderator", EDITOR => "Editor", USER => "User");
        $form->setFormField($form->inputLabel("ulevel", "User Level"), $form->selectOptions("ulevel", $level_options, $process->post("ulevel", $ulevel)), $validate->displayErrorField($process->errorinfo, "ulevel"));
        //User Status
        $form->setFormField($form->inputLabel("status", "Status"), $form->radioButton("Active", "status", "active", $process->post("status", $status) == "active" ? true : false) . $form->radioButton("Inactive", "status", "inactive", $process->post("status", $status) == "inactive" ? true : false) . $form->radioButton("Banned", "status", "banned", $process->post("status", $status) == "banned" ? true : false));
    }
    //if in edit mode
    if ($GLOBALS["action"] != "editregister" && $GLOBALS["action"] != "edituser") {
        //Password
        $form->setFormField($form->inputLabel("password", "Password"), $form->inputField("password", "password", $process->post("password")), $validate->displayErrorField($process->errorinfo, "password"));
        $form->setFormField($form->inputLabel("cpassword", "Confirm Password"), $form->inputField("password", "cpassword", $process->post("cpassword")), $validate->displayErrorField($process->errorinfo, "cpassword"));
    }
    //Submit Form
    $hyperlink = GenerateUrl::buildLink("..", ".", "Terms and Conditions of use", "target=terms.html");
    //checks submit type
    if ($GLOBALS["action"] == "editregister") {
        $form->setFormField(null, $form->inputField("submit", "send", "Update My Profile "));
    } elseif ($GLOBALS["action"] == "edituser") {
        $form->setFormField(null, $form->inputField("submit", "send", "Update User Account "));
    } else {
        $form->setFormField(null, $form->addFormInfo("<strong role=\"agreement\">By Clicking on Register you Agree to our {$hyperlink}.</strong>"));
        $form->setFormField(null, $form->inputField("submit", "send", "Register"));
    }
    $form->endForm();
    return $form->DisplayFields($GLOBALS["form_labling"], $process->message);
}