<?php
defined('_VALID') or die('Restricted access ');
if ($_REQUEST['fk_recid'] == '') {
    $configObj->glLibraryObj->header_redirect('index.php');
}
include_once('class.pagephoto.php');
$photogalleryObj = new pagephoto($configObj);
$action = $_REQUEST['action'];
$view = $_REQUEST['view'];
$configObj->glTplObj->set('modulename', $modulename);
$configObj->glTplObj->set('pageTab', true);
$photogalleryObj->intitialize($view);
$configObj->glTplObj->change_path($configObj->currentModulePath . 'html/templates/');
$configObj->glTplObj->set('configObj', $configObj);
$configObj->glTplObj->set('photogalleryObj', $photogalleryObj);

switch ($modulename) {
    case 'activity':
        $moduletabsel = 'activityTab';
        $moduletitle = 'Activities';
        break;
    case 'menu':
        $moduletabsel = 'menuTab';
        $moduletitle = 'Menus';
        break;

    case 'menuitem':
        $moduletabsel = 'menuTab';
        $moduletitle = 'Menus Item';
        break;

    default:
        $moduletabsel = 'pagesTab';
        $moduletitle = 'Pages';
        break;
}

$configObj->glTplObj->set('moduletitle', $moduletitle);
$configObj->glTplObj->set($moduletabsel, true);

switch ($action) {
    case 'add':

        $photogalleryObj->eid = $_REQUEST['eid'];
		
        if ($_REQUEST['h_save'] == 'T') {
            $photogalleryObj->varpostdata = $_REQUEST;
            $photogalleryObj->insert_photo();

            $configObj->glLibraryObj->header_redirect('index.php?module=pagephoto&tname=' . $_REQUEST['tname'] . '&fk_recid=' . $_REQUEST['fk_recid'] . '&msg=add');
        } else {
            $photogalleryObj->pagename = 'index.php?module=pagephoto';
            $photogalleryObj->Generateurl();

            if ($_REQUEST['msg'] == 'add') {
                $messagebox = $photogalleryObj->configObj->glLibraryObj->message("Congrats! The record is successfully saved.");
                $photogalleryObj->configObj->glTplObj->set('messagebox', $messagebox);
            } else if ($_REQUEST['msg'] == 'edit') {
                $messagebox = $photogalleryObj->configObj->glLibraryObj->message("Congrats! The data has been successfully edited and saved.");
                $photogalleryObj->configObj->glTplObj->set('messagebox', $messagebox);
            }
            if ($modulename == 'activity' || $modulename == 'menu') {
                $configObj->adminContentPanel = $configObj->glTplObj->process('pagephoto_add.tpl.php');
            } else {
                $configObj->adminContentPanel = $configObj->glTplObj->process('pagephoto_add.tpl.php');
            }
        }
        break;

    case 'edit':

        $photogalleryObj->pagename = 'index.php?module=pagephoto'; // Attribute of Page Name
        $photogalleryObj->Generateurl();
        if ($_REQUEST['h_save'] == 'T') {
            $photogalleryObj->varpostdata = $_REQUEST;

            if ($photogalleryObj->update_photos()) {
                $configObj->glLibraryObj->header_redirect('index.php?module=pagephoto&tname=' . $_REQUEST['tname'] . '&fk_recid=' . $_REQUEST['fk_recid'] . '&msg=edit');
            }
        }
        if ($_REQUEST['msg']) {
            if ($_REQUEST['msg'] == 'add') {
                $messagebox = $photogalleryObj->configObj->glLibraryObj->message("Congrats! The record has been successfully saved.");
                $photogalleryObj->configObj->glTplObj->set('messagebox', $messagebox);
            } else if ($_REQUEST['msg'] == 'edit') {
                $messagebox = $photogalleryObj->configObj->glLibraryObj->message("Congrats! The record has been successfully edited and saved.");
                $photogalleryObj->configObj->glTplObj->set('messagebox', $messagebox);
            }
        }
        $row = $photogalleryObj->select_photo($_REQUEST['eid']);

        $photogalleryObj->configObj->glTplObj->set('row', $row);
        $configObj->adminContentPanel = $configObj->glTplObj->process('pagephoto_add.tpl.php');
        break;

    case 'delete':
        if ($configObj->isAjaxSet) {

            $photogalleryObj->is_photoused($photogalleryObj->fk_module);
        }
        break;

    case 'updatephototitle':
        $photogalleryObj->update_photogallery_title('18', $_REQUEST['eid']);
        break;

    default:
        $photogalleryObj->load_photogallery();
        break;
}
?>
