· 7 years ago · Dec 05, 2018, 10:56 PM
1<?php
2/**
3 * @file
4 * This file contains the code to edit a §site.
5 *
6 * @cond $HeadURL: svn+ssh://dregal@svnthis-companynw/var/svn/this-company/admin/david/src/site_edit.php $ @endcond
7 * $Id: site_edit.php 1965 2012-08-17 02:18:56Z dregal $
8 *
9 */
10
11require_once('include.inc');
12require_once('Site.class.inc');
13
14// debug
15$debug = false;
16
17$errors = $warnings = array();
18
19function top_level_handler($exception)
20{
21 echo "<b>ERROR: Uncaught Exception occurred:</b> " . $exception->getMessage();
22}
23
24set_exception_handler('top_level_handler');
25
26//-----------------------------------------------------------------------------
27//
28// Functions
29//
30//-----------------------------------------------------------------------------
31
32//-----------------------------------------------------------------------------
33/**
34Show the edit form for a site item. Without additional programming,
35This form will not work to create new sites, but works to edit an
36existing one.
37 */
38function edit_site_form( $id, $cgiFields, &$errors)
39{
40 // Error count is returned and helps determine
41 // whether or not to add an error message to the error array.
42 $error_ct = 0;
43 // 1 or not empty value = show fields. empty, null, false, etc = hide fields
44 $bShowFieldsDB = @$cgiFields['show_fields_db'];
45 // Site object
46 $oSite = null;
47 // Input fields are controlled depending on the delete option
48 $bDelete = ( 'on' == @$cgiFields['delete'] );
49 // Cast $id to integer
50 $id = (int) $id;
51
52 //
53 // if we are editing the site item, then
54 // load the necessary objects.
55 //
56 $oSite = new Site();
57 // Load the object if an $id was given
58 if ( 0 != $id )
59 {
60 $oSite->Get($id);
61
62 }
63 else
64 {
65 // new site
66 }
67
68 // Get a list of Abbreviations to show for resync options
69 // Default is blank
70 $ary_site_abbreviation = $oSite->GetArrayResyncDestinationsPossibilities();
71
72 echo '<form action="site_edit.php" method="POST">';
73 // Show the form if not a delete operation
74 if ( $bDelete == false )
75 {
76 $oBranch = new Branch();
77 $ary_branch_id = $oBranch->GetArrayBranches("", true);
78
79 echo '
80 <table>
81 <tr>
82 <td class="rhead">Abbreviations: </td>
83 <td>
84 ';
85
86 if ( 0 != $id )
87 {
88
89 // Show table of abbreviations if the site has them.
90 $siteAddressObjList = $oSite->GetSiteAddresses();
91 // Show all the items we found
92 //
93 if ( $siteAddressObjList )
94 {
95 echo '<table>';
96 $rt = 0;
97 // print header
98 echo '<tr class="chead">';
99 echo '<td>Abbreviation</td>';
100 echo '</tr>';
101 foreach ( $siteAddressObjList as $oSiteAddress )
102 {
103 // Flip the bit in $rt toggle, so it alternates between zero and one.
104 $rt ^= 1;
105 echo '<tr class="row'. $rt .'">';
106
107 echo '<td><a href="site_address_edit.php?id=' . $oSiteAddress->GetID() .
108 '" title="Site Address ID: ' . $oSiteAddress->GetID() .
109 ', Site ID: '. $oSiteAddress->GetSiteID() .
110 '" target="_blank">' . $oSiteAddress->GetAddress() . '</a></td>';
111 echo '<td>', html_checkbox("deleted_site_address_" . $oSiteAddress->GetID(), 0, ' Delete'), ' </td>';
112
113 // end of the row
114 echo '</tr>';
115 }
116 echo '</table>';
117 // Drop-down select for Default Site Address
118 echo '<tr>
119 <td class="rhead">Default Abbreviation: </td>
120 <td>
121 ', html_select_array( "default_site_address_id", $oSite->GetArraySiteAddress(), $oSite->GetDefaultSiteAddressID(), 0, "id=\"default_site_address_id\""), '
122 </td>
123 </tr>
124 ';
125 }
126 else
127 {
128 echo '<i>none</i>';
129 }
130 }
131
132 echo '
133 </td>
134 </tr>
135 <tr>
136 <td class="rhead">Add Abbreviation: </td>
137 <td>
138 <input name="site_address" id="site_address" type="text" size="32" maxlength="32" value="" />
139 <br /><i>(Only supports one new abbreviation at a time.)</i>
140 </td>
141 </tr>
142 ';
143
144 echo '
145 <tr>
146 <td class="rhead">Site Name: </td>
147 <td>
148 <input name="site_name" id="site_name" type="text" size="32" maxlength="255" value="', $oSite->GetName() ,'" />
149 <br /><i>(Do not use abbreviations. This is how the site will appear on the index page.).</i>
150 </td>
151 </tr>
152 <tr>
153 <td class="rhead">Site School District: </td>
154 <td>
155 <input name="site_district" id="site_district" type="text" size="32" maxlength="255" value="', $oSite->site_district , '" />
156 <br /><i>(This is how the district will appear on the index page.).</i>
157 </td>
158 </tr>
159 ';
160 if ( 0 != $id )
161 {
162 echo '
163 <tr>
164 <td class="rhead">Database Fields: </td>
165 <td>
166 ';
167 if ( $bShowFieldsDB )
168 {
169 echo '
170 <table>
171 <input name="submitted_fields_db" id="submitted_fields_db" type="hidden" value="1" />
172 <tr>
173 <td>DB User: </td>
174 <td>
175 <input name="db_user" id="db_user" type="text" size="64" maxlength="64" value="', $oSite->db_user ,'" />
176 </td>
177 </tr>
178 <tr>
179 <td>DB Password: </td>
180 <td>
181 <input name="db_pass" id="db_pass" type="text" size="64" maxlength="64" value="', $oSite->db_pass ,'" />
182 </td>
183 </tr>
184 <tr>
185 <td>DB Host: </td>
186 <td>
187 <input name="db_host" id="db_host" type="text" size="64" maxlength="64" value="', $oSite->db_host ,'" />
188 </td>
189 </tr>
190 <tr>
191 <td>DB Name: </td>
192 <td>
193 <input name="db_name" id="db_name" type="text" size="64" maxlength="64" value="', $oSite->db_name ,'" />
194 </td>
195 </tr>
196 </table>
197 ';
198 }
199
200 echo
201 html_checkbox("show_fields_db", $bShowFieldsDB, "Show Database fields", 1, "id=\"show_fields_db\"") . '
202 </td>
203 </tr>
204 <tr>
205 <td class="rhead">User Banner: </td>
206 <td>
207 <textarea name="user_banner" id="user_banner" cols="60" rows="5">', $oSite->GetUserBanner() ,'</textarea>
208 <br /><i>(This banner is shown on all pages of a site, or shown as the reason for it being offline. User customizable.).</i>
209 </td>
210 </tr>
211 <tr>
212 <td class="rhead">Admin Banner: </td>
213 <td>
214 <textarea name="admin_banner" id="admin_banner" cols="60" rows="5">', $oSite->GetAdminBanner() ,'</textarea>
215 <br /><i>(This banner is shown on all pages of a site, or shown as the reason for it being offline. System admins.).</i>
216 </td>
217 </tr>
218 <tr>
219 <td class="rhead">Site Lockout (Site Flags): </td>
220 <td>
221 ' . html_checkbox("site_flags_user", $oSite->GetSiteFlagsUser() ,"Site offline due to user request", 1, "id=\"site_flags_user\"") . '<br />
222 ' . html_checkbox("site_flags_admin", $oSite->GetSiteFlagsAdmin() ,"Site offline for administrative reasons", 1, "id=\"site_flags_admin\"") . '<br />
223 Site Flags: ' . $oSite->GetSiteFlags() . '<br />
224 </td>
225 </tr>
226 <tr>
227 <td class="rhead">Site SQL: </td>
228 <td>
229 ' . html_checkbox("site_sql", $oSite->GetSiteSQL(), "Allow unprotected accounts to perform SQL queries", 1, "id=\"site_sql\"") . '
230 </td>
231 </tr>
232 <tr>
233 <td class="rhead">Debugging Features (Site Debug): </td>
234 <td>
235 ' . html_checkbox("site_debug", $oSite->GetSiteDebug(), "Enable basic debugging capabilities", 1, "id=\"site_debug\"") . '
236 </td>
237 </tr>
238 ';
239 }
240
241 echo '
242 <tr>
243 <td class="rhead">Site Display: </td>
244 <td>
245 ' . html_checkbox("site_display", $oSite->GetSiteDisplay(), "Show on homepage", 1, "id=\"site_display\"") . '
246 </td>
247 </tr>
248 <tr>
249 <td class="rhead">Site Type: </td>
250 <td>', html_select_array('site_type', Site::$enum_site_type, $oSite->GetSiteType(), 0, "id=\"site_type\" onchange=\"selected_site_type()\""), '</td>
251 </tr>
252 <tr>
253 <td class="rhead">Site Expires: </td>
254 <td>
255 ', Date::writeDateWidget('site_expires', $oSite->GetSiteExpiresEpoch() ), '
256 <br /><i>(Leave blank for a site that does not expire. The site will become unavailable to regular users after this date.)</i>
257 <br />', html_checkbox('site_expires_lockout', @$_REQUEST['site_expires_lockout'], ' Forbid admin logins after site expiration', 1, "id=\"site_expires_lockout\""), '
258 <br /><i>(Normally people with administrator accounts can still log in to an expired site. Check this option to disable this behavior. Protected accounts will still be able to log in.)</i>
259 </td>
260 </tr>
261 <tr>
262 <td class="rhead">Code Branch: </td>
263 <td>
264 ', html_select_array( "branch_id", $ary_branch_id, $oSite->GetBranchID(), 0, "id=\"branch_id\""), '
265 </td>
266 </tr>
267 <tr>
268 <td class="rhead">Resync: </td>
269 <td>', html_checkbox("resync_enabled", $oSite->GetResyncOriginSiteAddressID() != null ? "checked" : "",
270"Resync enabled.", 1, "id=\"resync_enabled\""), ' Origin: ', html_select_array( 'resync_origin', $ary_site_abbreviation, $oSite->GetResyncOriginSiteAddressID(), 0, "id=\"resync_origin\" onchange=\"edit_resync_origin()\"" ) , '
271 <br /><i>(Allows the content of this site to be periodically refreshed from the site it is a copy of. <b>Do not enable on Paid or Archived/Historical sites.</b>)</i>
272 <br />Resync Interval: <input type="text" id="resync_interval" name="resync_interval" maxlength="8" size="8" value="', $oSite->GetSiteResyncInterval() , '" /> seconds
273 <br /><i>(How long to wait between automatic resyncs. Leave blank to only allow manual resyncs.)</i>
274 ';
275 if ( 0 != $id )
276 {
277 echo '
278 <br />', html_checkbox("resync_now", "", "Resync now.", 1, "id=\"resync_now\""), '
279 ';
280 }
281
282 echo '
283 </td>
284 </tr>
285 ';
286 if ( 0 != $id ){
287 echo '
288 <tr>
289 <td class="rhead">ID: </td>
290 <td>' . $id . '</td>
291 </tr>
292 ';
293 }
294 echo '
295 </table>
296 ';
297 }
298
299 // include the id field, delete, and copy options if this item already exists.
300 if ( 0 != $id )
301 {
302 echo '<input type="hidden" value="' . $id . '" name="id" />';
303 if ( $bDelete == false )
304 {
305 // Give the use the option to delete. Delete checkbox.
306 echo '<input type="checkbox" name="delete" id="delete" onclick="edit_delete( this.checked)" />Delete?<br />';
307 // Copy (clone) checkbox
308 echo '<input type="checkbox" name="copy" id="copy" onclick="edit_copy( this.checked)" />Copy?<br />';
309 echo '<br /><br /><input type="submit" name="action" value="Save Changes" />';
310 }
311 else
312 {
313 echo "Site Name: ". $oSite->GetName() ."<br/>";
314 // Delete operation
315 // List sites using this site. <br/> If used, give user options, such as reassigning dependent records to a different parent. <br /></i>';
316 // Get a list of Sites that use this Site as a Resync Origin
317 try
318 {
319
320 if( $oSite->HasResyncDestination() )
321 {
322 echo '<h2>Resync Destinations</h2>';
323 $aResyncDestinations = $oSite->GetResyncDestinationNames();
324
325 echo '<table>';
326 $rt = 0;
327 // print header
328 echo '<tr class="chead">';
329 echo '<td>Site is used as a Resync Origin by: </td>';
330 echo '</tr>';
331 foreach( $aResyncDestinations as $destination )
332 {
333 // Flip the bit in $rt toggle, so it alternates between zero and one.
334 $rt ^= 1;
335 echo '<tr class="row'. $rt .'">';
336
337 echo "<td>$destination</td>";
338
339 //
340 // end of the row
341 echo '</tr>';
342 }
343 echo '</table>';
344 echo "<br />";
345
346 echo "Reassign resync destinations to: " . html_select_array( 'resync_origin', $oSite->GetResyncDestinationsPossibilities(), "", 0, "id=\"resync_origin\"" );
347 echo "<br />";
348 echo "<br />";
349 }
350
351 if ( $oSite->GetConfirmDeleteWarn() )
352 {
353 // Give a warning.
354 echo '<b> WARNING: You are about to delete a '. $oSite->GetSiteTypePretty() .' site. Proceed with caution.</b><br />';
355 }
356
357 if ( $oSite->GetConfirmDeleteWithSiteAddress() )
358 {
359 echo '<h2>Confirm with an Abbreviation</h2>';
360 echo 'Enter one abbreviation used by this site: <input name="delete_confirm_site_address" type="text" size="32" maxlength="32" value=""/>';
361 echo "<br />";
362 echo "<br />";
363
364 // Show table of abbreviations.
365 $siteAddressObjList = $oSite->GetSiteAddresses();
366 // Show all the items we found
367 if ( $siteAddressObjList )
368 {
369 echo '<table>';
370 $rt = 0;
371 // print header
372 echo '<tr class="chead">';
373 echo '<td>Abbreviation</td>';
374 echo '</tr>';
375 foreach ( $siteAddressObjList as $oSiteAddress )
376 {
377 // Flip the bit in $rt toggle, so it alternates between zero and one.
378 $rt ^= 1;
379 echo '<tr class="row'. $rt .'">';
380 echo '<td>' . $oSiteAddress->GetAddress() . '</td>';
381 // end of the row
382 echo '</tr>';
383 }
384 echo '</table>';
385 }
386 }
387 }
388 catch( Exception $ex )
389 {
390 $errors[] = "At line: " . __LINE__ . ". Failed " . $ex->getMessage();
391 $error_ct++;
392 }
393
394 // Confirm deletion
395 echo '<br /><br /><input type="submit" name="action" value="Delete" />';
396 // Cancel deletion
397 echo ' <input type="submit" name="action" value="Cancel" />';
398 }
399 }
400 echo '</form>';
401
402 return $error_ct;
403}
404
405// Description: Saves the changes or creates a new site. Modifies the $id variable.
406//-----------------------------------------------------------------------------
407function save_site( &$id, &$cgiFields, &$errors, &$warnings )
408{
409 // Check if this is a copy action
410 $bCopy = ( 'on' == @$cgiFields['copy'] );
411 // 1 or not empty value = show fields. empty, null, false, etc = hide fields
412 $bSubmittedFieldsDB = @$cgiFields['submitted_fields_db'];
413 // Cast $id to integer
414 $id = (int) $id;
415
416 // load the (source) site object.
417 if ( 0 != $id && $id != 0)
418 {
419 $oSite = new Site();
420 $oSite->Get($id);
421 }
422 else if ( $bCopy )
423 {
424 $errors[] = "Cannot copy before creation.";
425 }
426 else
427 {
428 $oSite = new Site();
429 }
430
431 if ( !$errors )
432 {
433 // Save or copy the changes to the object
434 $oSite->SetName( $cgiFields['site_name'] );
435 if ( ! empty( $cgiFields['default_site_address_id'] ) )
436 {
437 try
438 {
439 $oSite->SetDefaultSiteAddressID( @$cgiFields['default_site_address_id'] );
440 }
441 catch( Exception $ex)
442 {
443 $errors[] = "Caught exception in File: " . __FILE__ .
444 ", Line: " . __LINE__ . ".<br /> Message: " . $ex->getMessage();
445 }
446 }
447 $oSite->SetSiteDistrict($cgiFields['site_district']);
448 $oSite->SetUserBanner($cgiFields['user_banner']);
449 $oSite->SetAdminBanner($cgiFields['admin_banner']);
450 $oSite->SetSiteType($cgiFields['site_type']);
451 $oSite->SetSiteFlagsUser(@$cgiFields['site_flags_user']);
452 $oSite->SetSiteFlagsAdmin(@$cgiFields['site_flags_admin']);
453 if ($bSubmittedFieldsDB)
454 {
455 $oSite->SetDBUser(@$cgiFields['db_user']);
456 $oSite->SetDBPass(@$cgiFields['db_pass']);
457 $oSite->SetDBHost(@$cgiFields['db_host']);
458 $oSite->SetDBName(@$cgiFields['db_name']);
459 }
460 $oSite->SetSiteSQL(@$cgiFields['site_sql']);
461 $oSite->SetSiteDebug(@$cgiFields['site_debug']);
462 $oSite->SetSiteDisplay(@$cgiFields['site_display']);
463 try
464 {
465 $site_expires = Date::readDateWidget("site_expires");
466 }
467 catch (EmptyDateException $ex)
468 {
469 $site_expires = null;
470 }
471 catch (InvalidDateException $ex)
472 {
473 $errors[] = "Site Expires: " . HSC($ex->getMessage());
474 }
475 $oSite->SetSiteExpires($site_expires);
476
477 $oSite->SetSiteExpiresLockout(@$cgiFields['site_expires_lockout']);
478 $oSite->SetBranchID( $cgiFields['branch_id'] );
479 // Disable resync if we didn't ask to leave it on.
480 if (empty($cgiFields['resync_enabled']))
481 {
482 // @todo: Ask Daniel if OK to remove the 'Resync Enabled' checkbox and instead use the selection of an origin as indicator Resync is enabled.
483 // @todo: Check dependency between Resync Origin being blanked causing Resync Enabled to be blank.
484 // @todo: Resync Origin blank != Resync Enabled blank.
485 $oSite->SetResyncOrigin(null);
486 }
487 else
488 {
489 try
490 {
491 $oSite->SetResyncOrigin(@$cgiFields['resync_origin']);
492 }
493 catch( Exception $ex )
494 {
495 $errors[] = $ex->getMessage();
496 }
497 }
498 if ( !empty($_REQUEST['resync_now']) )
499 {
500 try
501 {
502 $oSite->Resync();
503 }
504 catch( Exception $ex )
505 {
506 $errors[] = $ex->getMessage();
507 }
508 }
509 try
510 {
511 // @todo: Warn if Resync enabled is checked but no resync origin was selected.
512 $oSite->SetResyncInterval(@$cgiFields['resync_interval']);
513 }
514 catch( Exception $ex )
515 {
516 $errors[] = $ex->getMessage();
517 }
518
519
520 if ( !$errors )
521 {
522 // Copy the changes to the object to a new object
523 if ( $bCopy === true )
524 {
525 try {
526 // create copy and get the id of the newly created site
527 $idCopy = $oSite->SaveNew();
528 }
529 catch( Exception $ex) {
530 $errors[] = "Caught exception in File: " . __FILE__ .
531 ", Line: " . __LINE__ . ".<br /> Message: " . $ex->getMessage();
532 }
533 }
534 else
535 {
536 // Save the changes
537 try
538 {
539 $oSite->Save();
540 }
541 catch( Exception $ex)
542 {
543 $errors[] = "Caught exception in File: " . __FILE__ .
544 ", Line: " . __LINE__ . ".<br /> Message: " . $ex->getMessage();
545 }
546 }
547
548 // Create a new Abbreviation (aka site address)
549 if ( !empty($cgiFields['site_address']) ){
550 try
551 {
552 $oSite->CreateSiteAddress( $cgiFields['site_address'] );
553 }
554 catch( Exception $e)
555 {
556 $errors[] = "Caught exception in File: " . __FILE__ .
557 ", Line: " . __LINE__ . ".<br/> Message: " . $e->getMessage();
558 }
559 if ( !$errors )
560 {
561 $oSite->Save();
562 }
563 }
564
565
566 // Delete site address if marked for deletion
567 // Show table of abbreviations if the site has them.
568 $siteAddressObjList = $oSite->GetSiteAddresses();
569 // Go through all the items we found
570 if ( $siteAddressObjList ){
571 foreach ( $siteAddressObjList as $oSiteAddress )
572 {
573 if( !empty($cgiFields["deleted_site_address_" . $oSiteAddress->GetID()]) )
574 {
575 $warnings[] = "Deleted Abbreviation: " . $oSiteAddress->GetAddress() . ", Abbr ID: " . $oSiteAddress->GetID();
576 // Delete the site address
577 if ( $oSiteAddress->Delete() === false )
578 {
579 $errors[] = "Error occurred when attempting to delete Abbreviation "
580 . $oSiteAddress->GetAddress() ;
581 $error_ct++;
582 }
583 else
584 {
585 // Site Address deleted successfully
586 // Clear the object from memory
587 unset( $oSiteAddress );
588 }
589 }
590 }
591 }
592 }
593 }
594
595 // Check for warnings
596 if ( !$errors )
597 {
598 $aSiteWarnings = $oSite->GetWarnings();
599 foreach ( $aSiteWarnings as $warning )
600 {
601 $warnings[] = "<b>" . $warning . "</b><br/>";
602 }
603 }
604
605 if ( $errors )
606 {
607 return false;
608 }
609 else
610 {
611 if ( $bCopy )
612 {
613 html_msg_success("Site copied successfully. Id of copy: $idCopy");
614 }
615 else
616 {
617 html_msg_success("Site saved successfully.");
618 }
619 $id = $oSite->GetID();
620 return true;
621 }
622}
623
624
625//-----------------------------------------------------------------------------
626function delete_site( $id, $cgiFields, &$errors)
627{
628 $error_ct = 0;
629 // Cast $id to integer
630 $id = (int) $id;
631 // load the site object.
632 if ( 0 != $id )
633 {
634 $oSite = new Site();
635 $oSite->Get($id);
636 }
637 else
638 {
639 $errors[] = "Invalid options given. Check values of ID: $id.";
640 $error_ct++;
641 }
642
643 if ( "Delete" === @$cgiFields['action'] && 0 === $error_ct )
644 {
645 $bDeleteConfirm = true;
646 // If applicable, check for Abbreviation here.
647 if ( $error_ct === 0 ){
648 //Confirm delete
649 if ( $oSite->GetConfirmDeleteWithSiteAddress() )
650 {
651 if ( !empty( $cgiFields['delete_confirm_site_address'] ) && $oSite->GetSiteAddress( $cgiFields['delete_confirm_site_address'] ) )
652 {
653 // Confirm the delete with an Abbreviation passed. Continue the delete action.
654 }
655 else
656 {
657 // Stop the delete action.
658 $bDeleteConfirm = false;
659 $errors[] = "Could not delete Site. Abbreviation not found: '". $cgiFields['delete_confirm_site_address'] ."' for site " . $oSite->GetName() ;
660 $error_ct++;
661 }
662 }
663 }
664 }
665 else
666 {
667 $bDeleteConfirm = false;
668 $errors[] = "Delete action not set.";
669 $error_ct++;
670 }
671
672 if ( $error_ct === 0 ){
673 // Delete the object
674 if ( $bDeleteConfirm === true )
675 {
676 try {
677 // Check if new resync origin was selected
678 if ( !empty($cgiFields['resync_origin']) )
679 {
680 $aResyncDestinations = $oSite->GetResyncDestinations();
681 foreach( $aResyncDestinations as $oSiteResyncDestination )
682 {
683 $oSiteResyncDestination->SetResyncOrigin( $cgiFields['resync_origin'] );
684 $oSiteResyncDestination->Save();
685 }
686 }
687 }
688 catch ( Exception $e)
689 {
690 throw new Exception("Could not resync destinations to use a new resync origin. Caught exception in File: " . __FILE__ . ", Line: "
691 . __LINE__ . ".<br/> Message: " . $e->getMessage() );
692 }
693
694 try {
695 if ( $oSite->Delete() === false )
696 {
697 $errors[] = "Error occurred when attempting to delete Site "
698 . $oSite->GetName() ;
699 $error_ct++;
700 }
701 else
702 {
703 // Site deleted successfully
704 // Clear the object from memory
705 unset( $oSite );
706 }
707 }
708 catch ( Exception $e)
709 {
710 throw new Exception("Could not delete site. Caught exception in File: " . __FILE__ . ", Line: "
711 . __LINE__ . ".<br/> Message: " . $e->getMessage() );
712 }
713 }
714 }
715
716 return $error_ct;
717}
718
719//-----------------------------------------------------------------------------
720//
721// Initialization
722//
723//-----------------------------------------------------------------------------
724
725// Get the ID
726$id = null;
727if ( 0 < strlen( @$_REQUEST['id'] ) && 0 != (int) $_REQUEST['id'] )
728{
729 $id = (int) $_REQUEST['id'];
730}
731
732// Get the delete option
733$bDelete = ( 'on' == @$_REQUEST['delete'] );
734
735
736// Page title
737if ( $id && !$bDelete )
738{
739 html_page_start("Edit Site");
740}
741else if ( $id && $bDelete )
742{
743 html_page_start("Confirm Delete Site");
744}
745else
746{
747 html_page_start("Create Site");
748}
749
750echo '<script type="text/javascript" src="site.js"></script>';
751if ( $id )
752{
753 if ( $debug )
754 {
755 echo "<p><i>Debug: Currently editing Site ID $id</i><p/>";
756 }
757}
758
759//-----------------------------------------------------------------------------
760//
761// if there is an 'action' field, then check if the Save Changes button was clicked.
762//
763//-----------------------------------------------------------------------------
764if ( 'Save Changes' == @$_REQUEST['action'] )
765{
766 // Saves or copies the site if not a delete
767 if ( !$bDelete )
768 {
769 if ( save_site( $id, $_REQUEST, $errors, $warnings ) === false )
770 {
771 $errors[] = "Save failed.";
772 }
773
774 }
775
776}
777else if ( 'Delete' == @$_REQUEST['action'] )
778{
779 // Delete confirmed
780 if ( delete_site( $id, $_REQUEST, $errors) != 0 )
781 {
782 $errors[] = "Could not delete the site.";
783 }
784 else
785 {
786 html_msg_success("Site deleted successfully.");
787 $id = null;
788 }
789}
790// else if ( 'Cancel' == @$_REQUEST['action'] ) // Do nothing
791
792if ($errors) html_msg_errors($errors);
793if ($warnings) html_msg_warnings($warnings);
794
795//----------------------------------------------------------------------------
796//
797// show the edit form.
798//
799//----------------------------------------------------------------------------
800if ( edit_site_form( $id, $_REQUEST, $errors) != 0 )
801{
802 html_msg_errors($errors);
803}
804
805
806if ($debug) {
807 error_reporting(E_ALL);
808}
809
810//
811// EOF
812?>