Changeset 837
- Timestamp:
- 01/19/07 13:57:06 (2 years ago)
- Files:
-
- devel/lib/templates.php (modified) (4 diffs)
- devel/units/templates/template_actions.php (modified) (1 diff)
- devel/units/templates/templates_view.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
devel/lib/templates.php
r831 r837 554 554 } 555 555 556 function templates_actions () {556 function templates_actions() { 557 557 558 558 global $CFG,$USER,$db; … … 579 579 } 580 580 if ($exists) { 581 $t = new StdClass; 582 $t->template_id = $id; 583 $t->ident = $USER->ident; 584 update_record('users',$t); 585 586 $messages[] = __gettext("Your current template has been changed."); 587 } 588 break; 581 $affected_areas = optional_param('affected_areas',0,PARAM_INT); 582 if(is_array($affected_areas)) { 583 foreach($affected_areas as $index => $value) { 584 //TODO - check security 585 set_field('users','template_id',$id,'ident',$value); 586 } 587 $messages[] = __gettext("The templates have been changed according to your choices."); 588 } else { 589 $messages[] = __gettext("No changes made as no area of change where selected!"); 590 } 591 } 592 break; 593 589 594 590 595 case "templates:save": 591 596 $template = optional_param('template'); 592 597 $id = optional_param('save_template_id',0,PARAM_INT); 593 $templatetitle = optional_param('templatetitle');598 $templatetitle = trim(optional_param('templatetitle')); 594 599 if (!empty($template) && !empty($id) && !empty($templatetitle)) { 595 600 unset($_SESSION['template_element_cache'][$id]); 596 601 $exists = record_exists('templates','ident',$id,'owner',$USER->ident); 597 602 if ($exists) { 598 $t = new StdClass; 599 $t->name = $templatetitle; 600 $t->ident = $id; 601 update_record('templates',$t); 603 set_field('templates','name',$templatetitle,'ident',$id); 602 604 delete_records('template_elements','template_id',$id); 603 $contents = optional_param('template'); 604 foreach ($contents as $name => $content) { 605 foreach($template as $name => $content) { 605 606 //TODO Fix this with PARAM_CLEANHTML or similar 606 $cleanname = $name;607 $cleancontent = $content;607 $cleanname = trim($name); 608 $cleancontent = trim($content); 608 609 if ($content != "" && $content != $template[$name]) { 609 610 $te = new StdClass; … … 618 619 } 619 620 break; 621 622 620 623 case "deletetemplate": 621 624 $id = optional_param('delete_template_id',0,PARAM_INT); … … 626 629 set_field('users', 'template_id', -1, 'template_id', $id); 627 630 delete_records('template_elements','template_id',$id); 628 delete_records('template ','ident',$id);631 delete_records('templates','ident',$id); 629 632 $messages[] = __gettext("Your template was deleted."); 630 633 } 631 634 break; 635 636 632 637 case "templates:create": 633 638 $based_on = optional_param('template_based_on',0,PARAM_INT); 634 $name = optional_param('new_template_name');635 if ( !empty($name)) { // $based_on can be empty, surely? -Penny639 $name = trim(optional_param('new_template_name')); 640 if (empty($CFG->disable_usertemplates) && !empty($name)) { 636 641 $t = new StdClass; 637 642 $t->name = $name; devel/units/templates/template_actions.php
r659 r837 1 1 <?php 2 global $USER, $CFG;3 2 // Actions 4 5 global $template; 6 7 if (isset($_REQUEST['action']) && logged_on && !$CFG->disable_templatechanging) { 8 9 switch($_REQUEST['action']) { 10 11 case "templates:select": 12 if (isset($_REQUEST['selected_template'])) { 13 $id = (int) $_REQUEST['selected_template']; 14 if ($id == -1) { 15 $exists = 1; 16 } else { 17 $exists = record_exists_sql('SELECT ident FROM '.$CFG->prefix.'templates t 18 WHERE ident = '.$id.' AND (owner = '.$USER->ident." OR public = 'yes')"); 19 } 20 if ($exists) { 21 if(sizeof($_REQUEST['affected_areas'])) { 22 foreach($_REQUEST['affected_areas'] as $index => $value) { 23 //TODO - check security 24 set_field('users','template_id',$id,'ident',$value); 25 } 26 $messages[] = __gettext("The templates have been changed according to your choices."); 27 } 28 else { 29 $messages[] = __gettext("No changes made as no area of change where selected!"); 30 } 31 } 32 } 33 break; 34 35 36 case "templates:save": 37 if ( 38 isset($_REQUEST['template']) 39 && isset($_REQUEST['save_template_id']) 40 && isset($_REQUEST['templatetitle']) 41 ) { 42 $id = (int) $_REQUEST['save_template_id']; 43 unset($_SESSION['template_element_cache'][$id]); 44 if (record_exists('templates','ident',$id,'owner',$USER->ident)) { 45 $templatetitle = trim($_REQUEST['templatetitle']); 46 set_field('templates','name',$templatetitle,'ident',$id); 47 delete_records('template_elements','template_id',$id); 48 foreach($_REQUEST['template'] as $name => $content) { 49 $te = new StdClass; 50 $te->name = trim($name); 51 $te->content = trim($content); 52 $te->template_id = $id; 53 $noslashname = stripslashes($te->name); 54 $noslashcontent = stripslashes($te->content); 55 if ($noslashcontent != "" && $noslashcontent != $template[$noslashname]) { 56 insert_record('template_elements',$te); 57 } 58 } 59 $messages[] = __gettext("Your template has been updated."); 60 } 61 } 62 break; 63 64 65 case "deletetemplate": 66 if ( 67 isset($_REQUEST['delete_template_id']) 68 ) { 69 $id = (int) $_REQUEST['delete_template_id']; 70 unset($_SESSION['template_element_cache'][$id]); 71 if (record_exists('templates','ident',$id,'owner',$USER->ident)) { 72 set_field('users','template_id',-1,'template_id',$id); 73 delete_records('template_elements','template_id',$id); 74 delete_records('templates','ident',$id); 75 $messages[] = __gettext("Your template was deleted."); 76 } 77 } 78 break; 79 80 81 case "templates:create": 82 $name = optional_param('new_template_name'); 83 $based_on = optional_param('template_based_on',0,PARAM_INT); 84 if (empty($CFG->disable_usertemplates) && !empty($name)) { 85 $t = new StdClass; 86 $t->name = trim($name); 87 $t->owner = $USER->ident; 88 $t->public = 'no'; 89 $new_template_id = insert_record('templates',$t); 90 if (!empty($based_on) && $based_on != -1) { 91 if (record_exists_sql('SELECT ident FROM '.$CFG->prefix.'templates t 92 WHERE ident = '.$based_on.' AND (owner = '.$USER->ident." OR public = 'yes')")) { 93 if ($elements = get_records('template_elements','template_id',$based_on)) { 94 foreach($elements as $element) { 95 $te = new StdClass; 96 $te->name = addslashes($element->name); 97 $te->content = addslashes($element->content); 98 $te->template_id = $new_template_id; 99 insert_record('template_elements',$te); 100 } 101 } 102 } 103 } 104 } 105 break; 106 107 } 108 109 } 110 3 // backwards compatibility 4 templates_actions(); // in lib/templates.php 5 111 6 ?> devel/units/templates/templates_view.php
r659 r837 38 38 $name .=" /> "; 39 39 $column1 = "<h4>" . $template['name'] . "</h4>"; 40 $column2 = "<a href=\"".url."_templates/preview.php?template_preview=".$template['id']."\" target=\"preview\">" . __gettext(" preview") . "</a>";40 $column2 = "<a href=\"".url."_templates/preview.php?template_preview=".$template['id']."\" target=\"preview\">" . __gettext("Preview") . "</a>"; 41 41 $panel .= templates_draw(array( 42 42 'context' => 'adminTable',
