Create a new presentation object file named admin_departments.php in the presentation folder, and
add the following code to it:
// Class that supports departments admin functionality
class AdminDepartments
{
// Public variables available in smarty template
public $mDepartmentsCount;
public $mDepartments;
public $mErrorMessage;
public $mEditItem;
public $mLinkToDepartmentsAdmin;
// Private members
private $_mAction;
private $_mActionedDepartmentId;
// Class constructor
public function __construct()
{
// Parse the list with posted variables
foreach ($_POST as $key => $value)
// If a submit button was clicked ...
if (substr($key, 0, 6) == 'submit')
{
/* Get the position of the last '_' underscore from submit
button name e.g strtpos('submit_edit_dept_1', '_') is 17 */
$last_underscore = strrpos($key, '_');
CHAPTER 10 ?– CATALOG ADMINISTRATION: DEPARTMENTS AND CATEGORIES 288
/* Get the scope of submit button
(e.g 'edit_dep' from 'submit_edit_dept_1') */
$this->_mAction = substr($key, strlen('submit_'),
$last_underscore - strlen('submit_'));
/* Get the department id targeted by submit button
(the number at the end of submit button name)
e.g '1' from 'submit_edit_dept_1' */
$this->_mActionedDepartmentId = substr($key, $last_underscore + 1);
break;
}
$this->mLinkToDepartmentsAdmin = Link::ToDepartmentsAdmin();
}
public function init()
{
// If adding a new department .
Pages:
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408