Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
ees_login_design.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/designs/design/design.inc';
19 
31 class EES_Login_Design extends Design
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
59  public function create(Array &$link)
60  {
61  require_once SQ_CORE_PACKAGE_PATH.'/system/system_asset_fns.inc';
62  if (!system_asset_fns_create_pre_check($this)) {
63  return FALSE;
64  }
65  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
66  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
67 
68  if ($linkid = parent::create($link)) {
69  // NOTE: need to restore first so that dependant assets are created, and the cleanup can catch them to
70  if (!$this->restoreLoginDesign() || !system_asset_fns_create_cleanup($this)) {
71  $linkid = FALSE;
72  }
73  }
74 
75  if ($linkid) {
76  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
77  } else {
78  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
79  }
80 
81  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
82  return $linkid;
83 
84  }//end create()
85 
86 
93  public function restoreLoginDesign()
94  {
95  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
96  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
97 
98  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
99  if (!create_directory($this->data_path)) {
100  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
101  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
102  return FALSE;
103  }
104 
105  if (!create_directory($this->data_path_public)) {
106  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
107  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
108  return FALSE;
109  }
110 
111  $source_dir = dirname(__FILE__).'/design_files';
112 
113  $file_contents = file_to_string($source_dir.'/index.html');
114  if ($file_contents == '') {
115  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
116  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
117  trigger_localised_error('CORE0094', E_USER_WARNING);
118  return FALSE;
119  }
120 
121  $ef = $this->getEditFns();
122 
123  $parse_file = $this->data_path.'/parse.txt';
124  $file_exists = file_exists($parse_file);
125 
126  // OK what we are doing here is making sure that our MySource tags match up with what is being
127  // expected by all design areas
128  $file_contents = str_replace(Array('<MySource', '</MySource'), Array('<'.$ef->tag_name, '</'.$ef->tag_name), $file_contents);
129  if (!string_to_file($file_contents, $parse_file)) {
130  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
131  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
132  trigger_localised_error('CORE0095', E_USER_WARNING);
133  return FALSE;
134  }
135 
137  // File Versioning //
139 
140  // add the parse.txt file to the repository
141 
142  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
143 
144  if (!$file_exists) {
145  // attempt to add the file to the repository
146  if (!$fv->add($this->data_path_suffix, $parse_file, '')) {
147  trigger_localised_error('CORE0025', E_USER_WARNING);
148  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
149  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
150  return FALSE;
151  }
152  } else {
153  // updating existing file
154  $file_status = $fv->upToDate($parse_file);
155  if (FUDGE_FV_MODIFIED & $file_status) {
156  if (!$fv->commit($parse_file, '')) {
157  trigger_localised_error('CORE0033', E_USER_WARNING);
158  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
159  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
160  return FALSE;
161  }
162  }
163  }
164 
165  // make sure we have the latest version of our file
166  if (!$fv->checkOut($this->data_path_suffix.'/parse.txt', $this->data_path)) {
167  trigger_localised_error('CORE0031', E_USER_WARNING);
168  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
169  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
170  return FALSE;
171  }
172 
173  // attach the files that we need for the login design
174  if ($handle = opendir($source_dir.'/files')) {
175  while (FALSE !== ($file = readdir($handle))) {
176  // skip some "files" that we dont want to attach
177  if ($file == '.' || $file == '..' || strtoupper($file) == 'CVS') {
178  continue;
179  }
180 
181  $info = Array();
182  $info['name'] = $file;
183  $info['tmp_name'] = $source_dir.'/files/'.$file;
184  $info['non_uploaded_file'] = TRUE;
185  if (!$ef->_processUploadedFile($this, $info)) {
186  trigger_localised_error('CORE0030', E_USER_WARNING, $file);
187  }
188  }
189  closedir($handle);
190  }
191 
192  if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($this->id, 'all')) {
193  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
194  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
195  return FALSE;
196  }
197 
198  // First process the design
199  if (!$ef->parseAndProcessFile($this)) {
200  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
201  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
202  return FALSE;
203  }
204 
205  // Now use it to generate the design file
206  $this->generateDesignFile(FALSE);
207 
208  // make ourselves LIVE
209  if (!$this->processStatusChange(SQ_STATUS_LIVE)) {
210  trigger_localised_error('CORE0062', E_USER_WARNING);
211  }
212 
213  // Give public user read permission - we have to do this differently though,
214  // because the system assets list won't have been saved yet
215  $public_userids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('public_user');
216  if (!$GLOBALS['SQ_SYSTEM']->am->setPermission($this->id, $public_userids[0], SQ_PERMISSION_READ, '1')) {
217  trigger_localised_error('CORE0060', E_USER_WARNING);
218  }
219 
220  $GLOBALS['SQ_SYSTEM']->am->releaseLock($this->id, 'all');
221 
222  $dependants = $GLOBALS['SQ_SYSTEM']->am->getDependantChildren($this->id);
223  foreach ($dependants as $dependantid => $dependant_data) {
224  $dep_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($dependantid, $dependant_data[0]['type_code']);
225  if (!$GLOBALS['SQ_SYSTEM']->am->acquireLock($dep_asset->id, 'permissions')) {
226  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
227  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
228  return FALSE;
229  }
230  if (!$dep_asset->processStatusChange(SQ_STATUS_LIVE)) {
231  trigger_localised_error('CORE0061', E_USER_WARNING, $dep_asset->name, $dep_asset->id);
232  }
233  if (!$GLOBALS['SQ_SYSTEM']->am->setPermission($dep_asset->id, $public_userids[0], SQ_PERMISSION_READ, '1')) {
234  trigger_localised_error('CORE0059', E_USER_WARNING, $dep_asset->name, $dep_asset->id);
235  }
236  $GLOBALS['SQ_SYSTEM']->am->releaseLock($dep_asset->id, 'permissions');
237  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($dep_asset);
238  }
239 
240  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
241  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
242  return TRUE;
243 
244  }//end restoreLoginDesign()
245 
246 
254  public function _getAllowedLinks()
255  {
256  $ret_val = parent::_getAllowedLinks();
257  // can't have any customisations
258  unset($ret_val[SQ_LINK_TYPE_2]['design_customisation']);
259  return $ret_val;
260 
261  }//end _getAllowedLinks()
262 
263 
264 
265 }//end class
266 ?>