-
Notifications
You must be signed in to change notification settings - Fork 6
/
do_info_edit.php
60 lines (46 loc) · 1.7 KB
/
do_info_edit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
include_once("includes/inc.global.php");
include_once("classes/class.info.php");
include("includes/inc.forms.php");
$cUser->MustBeLevel(1);
$p->site_section = EVENTS;
$pg = cInfo::LoadOne($_REQUEST["id"]);
$p->page_title = _("Edit")." '". $pg["title"] ."'";
//
// First, we define the form
//
$form->addElement("hidden","id",$_REQUEST["id"]);
$form->addElement("text", "title", _("Title"), array("size" => 35, "maxlength" => 100));
$form->addElement("textarea", "description", _("Content"), array("cols"=>65, "rows"=>20, "wrap"=>"soft"));
// Note that CKEditor may also submit the form.
$form->addElement("submit", "btnSubmit", _("Submit"));
//
// Set up validation rules for the form
//
$form->addRule("title",_("Enter a title"),"required");
$form->addRule("description",_("Enter some body text"),"required");
//
// Then check if we are processing a submission or just displaying the form
//
if ($form->validate()) { // Form is validated so processes the data
$form->freeze();
$form->process("process_data", false);
} else {
$current_values = array ("title"=>$pg["title"], "description"=>$pg["body"]);
$form->setDefaults($current_values);
$p->DisplayPage($form->toHtml()); // just display the form
$p->InsertCKEditor("description");
}
//
// The form has been submitted with valid data, so process it
//
function process_data ($values) {
global $p, $cErr, $cDB;
$q = 'UPDATE cdm_pages set date='.time().', title='.$cDB->EscTxt($values["title"]).', body='.$cDB->EscTxt($values["description"]).' where id='.$cDB->EscTxt($values["id"]).'';
$success = $cDB->Query($q);
if ($success)
$output = _("Changes saved.");
else
$output = _("There was a problem saving the page.");
$p->DisplayPage($output);
}