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

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

importing elgg-0.1.1a

Line 
1 <?php
2
3     // Actions
4
5         global $template;
6         
7         if (isset($_REQUEST['action']) && logged_on) {
8             
9             switch($_REQUEST['action']) {
10                 
11                 case "templates:select":    if (isset($_REQUEST['selected_template'])) {
12                                             $id = (int) $_REQUEST['selected_template'];
13                                             if ($id == -1) {
14                                                 $exists = 1;
15                                             } else {
16                                                 $exists = db_query("select count(ident) as template_exists from templates where ident = $id and (owner = ".$_SESSION['userid']." or public='yes')");
17                                                 $exists = $exists[0]->template_exists;
18                                             }
19                                             if ($exists) {
20                                                 db_query("update users set template_id = $id where ident = " . $_SESSION['userid']);
21                                                 $messages[] = "Your current template has been changed.";
22                                             }
23                                         }
24                                         break;
25                 case "templates:save":
26                                         if (
27                                                 isset($_REQUEST['template'])
28                                                 && isset($_REQUEST['save_template_id'])
29                                                 && isset($_REQUEST['templatetitle'])
30                                             ) {
31                                                 $id = (int) $_REQUEST['save_template_id'];
32                                                 unset($_SESSION['template_element_cache'][$id]);
33                                                 $exists = db_query("select count(ident) as template_exists from templates where ident = $id and owner = ".$_SESSION['userid']);
34                                                 $exists = $exists[0]->template_exists;
35                                                 if ($exists) {
36                                                     $templatetitle = addslashes($_REQUEST['templatetitle']);
37                                                     db_query("update templates set name = '$templatetitle' where ident = $id");
38                                                     db_query("delete from template_elements where template_id = $id");
39                                                     foreach($_REQUEST['template'] as $name => $content) {
40                                                         $slashname = addslashes($name);
41                                                         $slashcontent = addslashes($content);
42                                                         if ($content != "" && $content != $template[$name]) {
43                                                             db_query("insert into template_elements set name='$slashname', content = '$slashcontent', template_id = $id");
44                                                         }
45                                                     }
46                                                     $messages[] = "Your template has been updated.";
47                                                 }
48                                             }
49                                         break;
50                 case "deletetemplate":    if (
51                                                 isset($_REQUEST['delete_template_id'])
52                                             ) {
53                                                 $id = (int) $_REQUEST['delete_template_id'];
54                                                 unset($_SESSION['template_element_cache'][$id]);
55                                                 $exists = db_query("select count(ident) as template_exists from templates where ident = $id and owner = ".$_SESSION['userid']);
56                                                 $exists = $exists[0]->template_exists;
57                                                 if ($exists) {
58                                                     db_query("update users set template_id = -1 where template_id = $id");
59                                                     db_query("delete from template_elements where template_id = $id");
60                                                     db_query("delete from templates where ident = $id");
61                                                     $messages[] = "Your template was deleted.";
62                                                 }
63                                             }
64                                         break;
65                 case "templates:create":
66                                         if (
67                                                 isset($_REQUEST['new_template_name'])
68                                                 && isset($_REQUEST['template_based_on'])
69                                             ) {
70                                                 $based_on = (int) $_REQUEST['template_based_on'];
71                                                 $name = addslashes($_REQUEST['new_template_name']);
72                                                 db_query("insert into templates set name = '$name', public = 'no', owner = " . $_SESSION['userid']);
73                                                 $new_template_id = db_id();
74                                                 if ($based_on != -1) {
75                                                     $exists = db_query("select count(ident) as template_exists from templates where ident = $based_on and (owner = ".$_SESSION['userid']." or public = 'yes')");
76                                                     $exists = $exists[0]->template_exists;
77                                                     var_export($exists);
78                                                     if ($exists) {
79                                                         $elements = db_query("select * from template_elements where template_id = $based_on");
80                                                         if (sizeof($elements) > 0) {
81                                                             foreach($elements as $element) {
82                                                                 db_query("insert into template_elements set name = '".$element->name."', content = '".$element->content."', template_id = '".$new_template_id."'");
83                                                             }
84                                                         }
85                                                     }
86                                                 }
87                                             }
88                                         break;
89                 
90             }
91             
92         }
93
94 ?>
Note: See TracBrowser for help on using the browser.