| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
function template_pagesetup() { |
|---|
| 4 |
|
|---|
| 5 |
global $profile_id; |
|---|
| 6 |
global $PAGE; |
|---|
| 7 |
global $CFG; |
|---|
| 8 |
|
|---|
| 9 |
$page_owner = $profile_id; |
|---|
| 10 |
|
|---|
| 11 |
if (defined("context") && context == "account" && !$CFG->disable_templatechanging && user_info("user_type",$_SESSION['userid']) != "external") { |
|---|
| 12 |
if ($page_owner == $_SESSION['userid'] && $page_owner != -1) { |
|---|
| 13 |
$PAGE->menu_sub[] = array( 'name' => 'template:change', |
|---|
| 14 |
'html' => a_href( "{$CFG->wwwroot}mod/template/", |
|---|
| 15 |
__gettext("Change theme"))); |
|---|
| 16 |
} |
|---|
| 17 |
} |
|---|
| 18 |
|
|---|
| 19 |
$CFG->templates->variables_substitute['templatesroot'][] = "templates_root"; |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
function template_init() { |
|---|
| 23 |
global $CFG,$function; |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
$function['init'][] = dirname(__FILE__) . "/lib/default_template.php"; |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
$function['templates:init'][] = dirname(__FILE__) . "/lib/template_actions.php"; |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
$function['templates:draw'][] = dirname(__FILE__) . "/lib/template_draw.php"; |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
$function['templates:variables:substitute'][] = dirname(__FILE__) . "/lib/variables_substitute.php"; |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
$function['templates:draw:page'][] = dirname(__FILE__) . "/lib/page_draw.php"; |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
$function['templates:view'][] = dirname(__FILE__) . "/lib/templates_view.php"; |
|---|
| 42 |
$function['templates:preview'][] = dirname(__FILE__) . "/lib/templates_preview.php"; |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
$function['templates:edit'][] = dirname(__FILE__) . "/lib/templates_edit.php"; |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
$function['templates:add'][] = dirname(__FILE__) . "/lib/templates_add.php"; |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
listen_for_event("user","create","template_user_create"); |
|---|
| 52 |
|
|---|
| 53 |
listen_for_event("user","delete","template_user_delete"); |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
function templates_root($vars) { |
|---|
| 57 |
global $CFG; |
|---|
| 58 |
return $CFG->templatesroot; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
function template_user_create($object_type, $event, $object) { |
|---|
| 62 |
global $CFG; |
|---|
| 63 |
|
|---|
| 64 |
$object->template_name = $CFG->default_template; |
|---|
| 65 |
return $object; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
function template_user_delete($object_type, $event, $object) { |
|---|
| 69 |
global $CFG, $data; |
|---|
| 70 |
if (!empty($object->ident) && $object_type == "user" && $event == "delete") { |
|---|
| 71 |
if ($templates = get_records_sql("select * from {$CFG->prefix}templates where owner = {$object->ident}")) { |
|---|
| 72 |
foreach($templates as $template) { |
|---|
| 73 |
delete_records('template_elements','template_id',$template->ident); |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
delete_records('templates','owner',$object->ident); |
|---|
| 77 |
} |
|---|
| 78 |
return $object; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
?> |
|---|
| 82 |
|
|---|