Project

General

Profile

« Previous | Next » 

Revision 862

Added by aldus about 16 years ago

Modify to get informations where the template is in use when
a user try to uninstall it. Additional informations if the template is the standard-template.

View differences:

trunk/wb/admin/templates/uninstall.php
50 50
	$admin->print_error($MESSAGE['GENERIC']['NOT_INSTALLED']);
51 51
}
52 52

  
53
// Check if the template is in use
54
if($_POST['file'] == DEFAULT_TEMPLATE) {
55
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']);
53
if (!function_exists("replace_all")) {
54
	function replace_all ($aStr = "", &$aArray ) {
55
		foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
56
		return $aStr;
57
	}
58
}
59

  
60
/**
61
*	Check if the template is the standard-template or still in use
62
*/
63
$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE'] = "Can't unistall this template <b>".$file."</b> because it's the standardtemplate!";
64

  
65
if ($file == DEFAULT_TEMPLATE) {
66
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IS_DEFAULT_TEMPLATE']); /** Text is missing! 2008-06-15 */
67

  
56 68
} else {
57
	$query_templates = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE template = '".$admin->add_slashes($_POST['file'])."' LIMIT 1");
58
	if($query_templates->numRows() > 0) {
59
		$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']);
69
	
70
	/**
71
	*	Check if the template is still in use by a page ...
72
	*
73
	*	@version	0.2.0
74
	*	@build		5
75
	*	@author		aldus
76
	*	@since		0.1.0
77
	*	@lastchange 2008-10-23
78
	*
79
	*/
80
	$info = $database->query("SELECT page_id, page_title FROM ".TABLE_PREFIX."pages WHERE template='".$file."' order by page_title");
81
	
82
	if ($info->numRows() > 0) {
83
	
84
		/**
85
		*	Template is still in use, so we're collecting the page-titles
86
		*
87
		*	@version	0.2.0
88
		*	@build		5
89
		*	@since		0.1.1
90
		*	@lastchange 2008-10-23
91
		*
92
		*	0.2.0		Codechanges for Websitebaker to use it without the Black-Hawk-Engine
93
		*
94
		*	0.1.1		add this page <if we found only one> / these pages
95
		*
96
		*	@notice		All listed pages got linked to "settings.php" so the user can easy change
97
		*				the template-settings. Modifications could be made in "page_template_str".
98
		*				For additional informations you will have to modify the query, the page_template_str
99
		*				and the page_info array.
100
		*
101
		*	@todo		1 - Additional informations about the pages (modified, modified_by, visibility, etc)
102
		*
103
		*				2 - What happends about pages, the user is not allowed to edit?
104
		*					Marked "red"?
105
		*
106
		*				3 - Multiple language support here ...
107
		*/
108
		
109
		/**
110
		*	The base-message template-string for the top of the message
111
		*
112
		*	0.1.2	this page/ these pages
113
		*
114
		*/
115
		$add = $info->numRows() == 1 ? "this page" : "these pages";
116
		$msg_template_str  = "<br /><br />Template <b>{{template_name}}</b> could not be uninstalled because it is still in use by ";
117
		$msg_template_str .= $add.":<br /><i>click for editing.</i><br /><br />";
118
		
119
		/**
120
		*	The template-string for displaying the Page-Titles ... in this case as a link
121
		*/
122
		$page_template_str = "- <b><a href='../pages/settings.php?page_id={{id}}'>{{title}}</a></b><br />";
123
		
124
		$values = array ('template_name' => $file);
125
		$msg = replace_all ( $msg_template_str,  $values );
126
		
127
		$page_names = "";
128
		
129
		while ($data = $info->fetchRow(DB_FETCHMODE_ASSOC) ) {
130
			
131
			$page_info = array(
132
				'id'	=> $data['page_id'], 
133
				'title' => $data['page_title']
134
			);
135
			
136
			$page_names .= replace_all ( $page_template_str, $page_info );
137
		}
138
		
139
		/**
140
		*	Printing out the error-message and die().
141
		*/
142
		$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE'].$msg.$page_names);
60 143
	}
61 144
}
62 145

  

Also available in: Unified diff