<?php
defined('_VALID') or die('Restricted access');
include_once('class.photogallery.php');
$photogalleryObj = new photogallery($configObj);
$action = $_REQUEST['action'];
$photogalleryObj->intitialize($view);
$configObj->glTplObj->change_path($configObj->currentModulePath . 'html/templates/');
$configObj->glTplObj->set('configObj', $configObj);
$configObj->glTplObj->set('photogalleryObj', $photogalleryObj);
switch ($action) {
    case 'add':
        $configObj->glTplObj->set('fk_modules', 23);
        $photogalleryObj->varpostdata = $_REQUEST;
        $photogalleryObj->pagename = 'index.php?module=photogallery';
        if ($_FILES['var_image'] != '') {
            if ($photogalleryObj->insert_photo()) {
                $configObj->glLibraryObj->header_redirect('index.php?module=photogallery&fk_album='.$_REQUEST['fk_album'].'&msg=success');
            }
        }
        $configObj->adminContentPanel = $configObj->glTplObj->process('photogallery.tpl.php');
        break;
    case 'edit':
        $configObj->glTplObj->set('addphotoTab', true);
        $photogalleryObj->pagename = 'index.php?module=photogallery'; // 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=photogallery&msg=edit');
            }
        }
        if ($_REQUEST['msg']) {
            if ($_REQUEST['msg'] == 'add') {
                $messagebox = $photogalleryObj->configObj->glLibraryObj->message("The record has been successfully saved.");
                $photogalleryObj->configObj->glTplObj->set('messagebox', $messagebox);
            } else if ($_REQUEST['msg'] == 'edit') {
                $messagebox = $photogalleryObj->configObj->glLibraryObj->message("The record has been successfully edited and saved.");
                $photogalleryObj->configObj->glTplObj->set('messagebox', $messagebox);
            }
        }
        $row = $photogalleryObj->select_photo($_REQUEST['eid']);
        $albumArry = array();
        if (!empty($row)) {
            $albumArry = $photogalleryObj->getAlbum();
        }
        $photogalleryObj->configObj->glTplObj->set('albumArr', $albumArry);
        $photogalleryObj->configObj->glTplObj->set('row', $row);
        $configObj->adminContentPanel = $configObj->glTplObj->process('photogallery_edit.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;
case 'sharedata':

        if ($_REQUEST['h_save'] == 'T') {
          
            $photogalleryObj->varpostdata = $_REQUEST;
            echo $photogalleryObj->shareonfacebook();
        } else {
            echo $photogalleryObj->genrateshareOption();
        }
        exit;
        break;
        
    case 'fbalbum':
        $configObj->glTplObj->change_path($configObj->currentModulePath . 'facebookalbum/');
        echo $configObj->glTplObj->process('index.php');
        exit;
        break;

    
    case 'delphoto':
//        exit($_REQUEST['photoID']);
        $photogalleryObj->varpostdata = $_REQUEST;
        $photoID = $_REQUEST['photoID'];
        $albumID = $_REQUEST['fk_album'];
        $photogalleryObj->delete_image($photoID);
        ob_clean();
        echo "1";
        exit;
        break;

    case 'set_primary':
        $photogalleryObj->varpostdata = $_REQUEST;
        $photoID = $photogalleryObj->varpostdata['photoID'];
        $albumID = $photogalleryObj->varpostdata['fk_album'];
        if ($photogalleryObj->set_primary_photo($albumID)) {
            echo "1";
        } else {
            echo "0";
        }
        exit;
        break;

    case 'set_publish':
        $photogalleryObj->varpostdata = $_REQUEST;
        $photoID = $photogalleryObj->varpostdata['photoID'];
        $albumID = $photogalleryObj->varpostdata['fk_album'];
        $publish = $photogalleryObj->varpostdata['publish'];
        echo $photogalleryObj->set_publish($photoID, $albumID, $publish);
        if ($photogalleryObj->set_publish($photoID, $albumID, $publish)) {
            echo "1";
        } else {

            echo "0";
        }
        exit;
        break;

    case 'savealbumcaption':

        $photogalleryObj->varpostdata = $_REQUEST;
        $photoID = $photogalleryObj->varpostdata['photoID'];
        $albumID = $photogalleryObj->varpostdata['fk_album'];
        $photocaption = $photogalleryObj->varpostdata['photocaption'];
        if ($photogalleryObj->savePhotoCaption($photoID, $photocaption)) {
            echo "1";
       } else {
            echo "0";
        }
        exit;
        break;

    case 'set_photo_displayorder':
        $albumID = $photogalleryObj->varpostdata['fk_album'];
        $photogalleryObj->varpostdata = $_REQUEST;
        $photointglcode = $photogalleryObj->varpostdata['photointglcode'];
        if ($photogalleryObj->set_photo_displayorder($albumID, $photointglcode)) {
            echo "1";
        } else {
            echo "0";
        }
        exit;
        break;

    case 'photo_grid':
        $albumID = $_REQUEST['fk_album'];
        $configObj->glTplObj->set('photosArr', $photogalleryObj->getPhotosByAlbum($albumID));
        echo $configObj->glTplObj->process('photos_listing.tpl.php');
        exit;
        break;

    default:
        $albumID = $_REQUEST['fk_album'];
        $configObj->glTplObj->set('mngPhotoTab', true);
        $configObj->glTplObj->set('photosArr', $photogalleryObj->getPhotosByAlbum($albumID));
        $photogalleryObj->Generateurl();
        $configObj->glTplObj->set('frmaction', $photogalleryObj->urlwithpara . '&action=add');
        $photogalleryObj->load_photogallery();
        break;
}
?>