root/releases/0.1.1b/units/templates/templates_edit.php

Revision 2, 3.3 kB (checked in by sven, 3 years ago)

importing elgg-0.1.1a

Line 
1 <?php
2
3     global $template;
4     global $template_definition;
5     
6     if (!isset($parameter)) {
7     // Get template details
8         $template_id = db_query("select template_id from users where ident = " . $_SESSION['userid']);
9         if (sizeof($template_id) > 0) {
10             $template_id = $template_id[0]->template_id;
11         } else {
12             $template_id = -1;
13         }
14     } else {
15         if (!is_array($parameter)) {
16             $template_id = (int) $parameter;
17         } else {
18             $template_id = -1;
19         }
20     }
21
22     // Grab title, see if we can edit the template
23         $editable = 0;
24         if ($template_id == -1) {
25             $templatetitle = "Default Template";
26         } else {
27             $templatestuff = db_query("select * from templates where ident = $template_id");
28             $templatetitle = stripslashes($templatestuff[0]->name);
29             if ($templatestuff[0]->owner == $_SESSION['userid']) {
30                 $editable = 1;
31             }
32             if (($templatestuff[0]->owner != $_SESSION['userid']) && ($templatestuff[0]->public != 'yes')) {
33                 $template_id = -1;
34             }
35         }
36     
37     // Grab the template content
38         if ($template_id == -1) {
39             $current_template = $template;
40         } else {
41             $result = db_query("select * from template_elements where template_id = $template_id");
42             if (sizeof($result) > 0) {
43                 foreach($result as $element) {
44                     $current_template[stripslashes($element->name)] = stripslashes($element->content);
45                 }
46             } else {
47                 $current_template = $template;
48             }
49         }
50     
51     $run_result .= <<< END
52     
53     <form action="" method="post">
54     
55 END;
56     
57     $run_result .= run("templates:draw", array(
58                                                 'context' => 'databoxvertical',
59                                                 'name' => '<b>Template Name</b>',
60                                                 'contents' => run("display:input_field",array("templatetitle",$templatetitle,"text"))
61                                             )
62                                             );
63
64     foreach($template_definition as $element) {
65         
66         $name = "<b>" . $element['name'] . "</b><br /><i>" . $element['description'] . "</i>";
67         
68         if (sizeof($element['glossary']) > 0) {
69             $column1 = "<b>Glossary</b><br />";
70             foreach($element['glossary'] as $gloss_id => $gloss_descr) {
71                 $column1 .= $gloss_id . " -- " . $gloss_descr . "<br />";
72             }
73         } else {
74             $column1 = "";
75         }
76         
77         if ($current_template[$element['id']] == "" || !isset($current_template[$element['id']])) {
78             $current_template[$element['id']] = $template[$element['id']];
79         }
80         
81         $column2 = run("display:input_field",array("template[" . $element['id'] . "]",$current_template[$element['id']],"longtext"));
82 /*       
83         $run_result .= run("templates:draw", array(
84                                 'context' => 'databox',
85                                 'name' => $name,
86                                 'column2' => $column1,
87                                 'column1' => $column2
88                             )
89                             );
90 */
91         $run_result .= run("templates:draw", array(
92                                 'context' => 'databoxvertical',
93                                 'name' => $name,
94                                 'contents' => $column1 . "<br />" . $column2
95                             )
96                             );
97
98                                     
99     }
100     
101     if ($editable) {
102         $run_result .= <<< END
103     
104         <p align="center">
105             <input type="hidden" name="action" value="templates:save" />
106             <input type="hidden" name="save_template_id" value="$template_id" />
107             <input type="submit" value="Save" />
108         </p>   
109     
110 END;
111     } else {
112         $run_result .= <<< END
113         
114         <p>
115             You may not edit this template. To create a new, editable template
116             <i>based</i> on the default, go to <a href="index.php">the main templates page</a>.
117         </p>
118         
119 END;
120     }
121     $run_result .= <<< END
122         
123     </form>
124     
125 END;
126
127 ?>
Note: See TracBrowser for help on using the browser.