<?php
  /**
   * Copyright 2011 Zazavi - http://www.zazavi.com
   * Zazavi is free software released under the terms of the GNU General Public License.
   * You should have received a copy of the license.  If not, see <http://www.gnu.org/licenses/>.
     */
  if (!defined("_VALID_PHP"))
      die('Direct access to this location is not allowed.');
	  
  if(!$user->getAcl("Pages")): print $core->msgAlert(_CG_ONLYADMIN, false); return; endif;
?>
<?php include_once("help/pages.php");?>
<?php switch($core->action): case "edit": ?>
<?php $postrow = $content->getPosts();?>
<?php 
  require_once("modules/gallery/admin_class.php");
  $gal = new Gallery();
  $galrow = $gal->getGalleries();
  
  require_once(ZAZAVILITE . "lib/class_forms.php");
  $form = new Forms();  
?>
<h1><img src="images/pages-sml.png" alt="" /><?php echo _PG_TITLE1;?></h1>
<p class="info"><span><?php echo $core->langIcon();?></span><?php echo _PG_INFO1. _REQ1 . required(). _REQ2;?></p>
<h2><span><a href="javascript:void(0);" onclick="$('#dialog').dialog('open'); return false"><img src="images/help.png" alt="" /></a></span><?php echo _PG_SUBTITLE1 . $content->title;?></h2>
<form action="" method="post" id="admin_form" name="admin_form">
  <table cellspacing="0" cellpadding="0" class="formtable">
    <tr>
      <td width="200"><?php echo _PG_TITLE;?>: <?php echo required();?></td>
      <td><input name="title<?php echo $core->dblang;?>" type="text" class="inputbox required" value="<?php echo $content->title;?>" size="55" title="<?php echo _PG_TITLE_R;?>"/></td>
      <td rowspan="9" valign="top" class="postmenu">
	  <?php if($postrow == 0):?>
        <?php echo $core->msgAlert(_PG_NO_POSTS,false);?>
        <?php else:?>
        <div style="text-align:center">
          <h4><?php echo _PG_YES_POSTS;?></h4>
        </div>
        <ul id="postsort">
          <?php foreach ($postrow as $prow):?>
          <li id="pid_<?php echo $prow['id'];?>"><img src="images/handle.png" alt="" class="smallHandle" /> <a href="loader.php?do=posts&amp;action=edit&amp;postid=<?php echo $prow['id'];?>"><?php echo $prow['title'.$core->dblang];?></a></li>
          <?php endforeach;?>
        </ul>
        <?php unset($prow);?>
        <?php endif;?></td>
    </tr>
    <tr>
      <td><?php echo _PG_SLUG;?>:</td>
      <td><input name="slug<?php echo $core->dblang;?>" type="text" class="inputbox" value="<?php echo $content->slug;?>" size="55" />
      &nbsp; <?php echo tooltip(_PG_SLUG_T);?></td>
    </tr>
    <tr>
      <td><?php echo _PG_PUB;?>:</td>
      <td><span class="input-out">
        <label for="active-1"><?php echo _YES;?></label>
        <input name="active" type="radio" id="active-1" value="1" <?php getChecked($content->active, 1); ?> />
        <label for="active-2"><?php echo _NO;?></label>
        <input name="active" type="radio" id="active-2" value="0" <?php getChecked($content->active, 0); ?> />
        </span></td>
    </tr>
    <tr>
      <td><?php echo _PG_CC;?>:</td>
      <td><span class="input-out">
        <label for="contact_form-1"><?php echo _YES;?></label>
        <input name="contact_form" type="radio" id="contact_form-1" value="1" <?php getChecked($content->contact_form, 1); ?> />
        <label for="contact_form-2"><?php echo _NO;?></label>
        <input name="contact_form" type="radio" id="contact_form-2" value="0" <?php getChecked($content->contact_form, 0); ?> />
        <?php echo tooltip(_PG_CC_T);?></span></td>
    </tr>
    <tr>
      <td>Attach Custom Form:</td>
      <td><?php $formrow =  $form->getForms();?>
        <select name="cform" style="width:200px;" class="select">
        <option value="0">--- Select Form ---</option>
        <?php foreach ($formrow as $frow):?>
        <?php $sel = ($frow['id'] == $content->cform) ? " selected=\"selected\"" : '' ;?>
        <option value="<?php echo $frow['id'];?>"<?php echo $sel;?>><?php echo $frow['name'];?></option>
        <?php endforeach;?>
        </select></td>
    </tr>
    <tr>
      <td><?php echo _PG_GAL;?>:</td>
      <td><select class="select" name="gallery_id" style="width:200px">
          <option value="0"><?php echo _PG_GAL_SEL;?></option>
		  <?php if($galrow):?>
          <?php foreach($galrow as $grow):?>
          <?php $sel = ($grow['id'] == $content->gallery_id) ? ' selected="selected"' : '' ;?>
          <option value="<?php echo $grow['id'];?>"<?php echo $sel;?>><?php echo $grow['title'.$core->dblang];?></option>
          <?php endforeach;?>
          <?php unset($grow);?>
      <?php endif;?>
      </select></td>
    </tr>
    <tr>
      <td><?php echo _PG_COMMENTS;?>:</td>
      <td><span class="input-out">
        <label for="comments-1"><?php echo _YES;?></label>
        <input name="comments" type="radio" id="comments-1" value="1" <?php getChecked($content->comments, 1); ?> />
        <label for="comments-2"><?php echo _NO;?></label>
        <input name="comments" type="radio" id="comments-2" value="0" <?php getChecked($content->comments, 0); ?> />
        <?php echo tooltip(_PG_COMMENTS_T);?></span></td>
    </tr>
      <tr>
        <td><?php echo _PG_ACCESS_L;?>:</td>
        <td><?php echo $member->getAccessList($content->access);?></td>
      </tr>
      <tr id="memrow">
        <td><?php echo _PG_MEM_LEVEL;?>:</td>
        <td id="membership">
        <?php if($content->membership_id == 0):?>
        <?php echo _PG_NOMEM_REQ;?>
        <?php else:?>
		<?php echo $member->getMembersipList($content->membership_id);?>
		<?php endif;?>
        &nbsp;
        </td>
      </tr>
    <tr>
      <td><?php echo _PG_KEYS;?>:</td>
      <td><input name="keywords<?php echo $core->dblang;?>" type="text" class="inputbox" value="<?php echo $content->keywords;?>" size="55" />
        &nbsp;&nbsp; <?php echo tooltip(_PG_KEYS_T);?></td>
    </tr>
    <tr>
      <td><?php echo _PG_DESC;?>:</td>
      <td><textarea name="description<?php echo $core->dblang;?>" cols="55" rows="6"><?php echo $content->description;?></textarea></td>
    </tr>
    <tr>
      <td><input type="submit" name="submit" class="button" value="<?php echo _PG_UPDATE;?>" /></td>
      <td><a href="loader.php?do=pages" class="button-alt"><?php echo _CANCEL;?></a></td>
    </tr>
  </table>
  <input name="pageid" type="hidden" value="<?php echo $content->pageid;?>" />
</form>
<?php echo $core->doForm("processPage");?>
<script type="text/javascript"> 
// <![CDATA[
$(document).ready(function() {
    $('#access_id').change(function() {
        var option = $(this).val();
        var result = 'pageid=<?php echo $content->pageid;?>';
        result += '&membershiplist=' + option;
		  $.ajax({
			  type: "post",
			  url: "ajax.php",
			  data: result,
			  cache: false,
			  success: function (res) {
				  (option == "Membership") ? $('#memrow').show(): $('#memrow').hide();
				  $('#membership').html(res);
			  }
		  });
    });
	
    $("ul#postsort").sortable({
        handle: '.smallHandle',
		placeholder: 'modPlace',
        opacity: 0.6,
        helper: 'helper',
        update: function() {
            var order = $('ul#postsort').sortable('serialize');
            $.post("ajax.php?sortposts=1&" + order, function(theResponse) {
                $("#msgDisplay").html(theResponse);
            });
        }

    });
});
// ]]>
</script>
<?php break;?>
<?php case"add": ?>
<?php 
  require_once("modules/gallery/admin_class.php");
  $gal = new Gallery();
  $galrow = $gal->getGalleries();
  
  require_once(ZAZAVILITE . "lib/class_forms.php");
  $form = new Forms();  
?>
<h1><img src="images/pages-sml.png" alt="" /><?php echo _PG_TITLE2;?></h1>
<p class="info"><span><?php echo $core->langIcon();?></span><?php echo _PG_INFO2. _REQ1 . required(). _REQ2;?></p>
<h2><span><a href="javascript:void(0);" onclick="$('#dialog').dialog('open'); return false"><img src="images/help.png" alt="" /></a></span><?php echo _PG_SUBTITLE2;?></h2>
<form action="" method="post" id="admin_form" name="admin_form">
  <table cellspacing="0" cellpadding="0" class="formtable">
    <tr>
      <td width="200"><?php echo _PG_TITLE;?>: <?php echo required();?></td>
      <td><input name="title<?php echo $core->dblang;?>" type="text" class="inputbox required"  size="55" title="<?php echo _PG_TITLE_R;?>"/></td>
    </tr>
    <tr>
      <td><?php echo _PG_SLUG;?>:</td>
      <td><input name="slug<?php echo $core->dblang;?>" type="text" class="inputbox" size="55" />
      &nbsp; <?php echo tooltip(_PG_SLUG_T);?></td>
    </tr>
    <tr>
      <td><?php echo _PG_PUB;?>:</td>
      <td><span class="input-out">
        <label for="active-1"><?php echo _YES;?></label>
        <input name="active" type="radio" id="active-1" value="1" checked="checked" />
        <label for="active-2"><?php echo _NO;?></label>
        <input name="active" type="radio" id="active-2" value="0"  />
        </span></td>
    </tr>
    <tr>
      <td><?php echo _PG_CC;?>:</td>
      <td><span class="input-out">
        <label for="contact_form-1"><?php echo _YES;?></label>
        <input name="contact_form" type="radio" id="contact_form-1" value="1" />
        <label for="contact_form-2"><?php echo _NO;?></label>
        <input name="contact_form" type="radio" id="contact_form-2" value="0" checked="checked" />
        <?php echo tooltip(_PG_CC_T);?></span></td>
    </tr>
    <tr>
      <td>Attach Custom Form:</td>
      <td><?php $formrow =  $form->getForms();?>
        <select name="cform" style="width:200px;" class="select">
        <option value="0">--- Select Form ---</option>
        <?php foreach ($formrow as $frow):?>
        <option value="<?php echo $frow['id'];?>"><?php echo $frow['name'];?></option>
        <?php endforeach;?>
        </select></td>
    </tr>
    <tr>
      <td><?php echo _PG_GAL;?>:</td>
      <td><select class="select" name="gallery_id" style="width:200px">
          <option value="0"><?php echo _PG_GAL_SEL;?></option>
		  <?php if($galrow):?>
          <?php foreach($galrow as $grow):?>
          <option value="<?php echo $grow['id'];?>"><?php echo $grow['title'.$core->dblang];?></option>
          <?php endforeach;?>
          <?php unset($grow);?>
      <?php endif;?>
      </select></td>
    </tr>
    <tr>
      <td><?php echo _PG_COMMENTS;?>:</td>
      <td><span class="input-out">
        <label for="comments-1"><?php echo _YES;?></label>
        <input name="comments" type="radio" id="comments-1" value="1" />
        <label for="comments-2"><?php echo _NO;?></label>
        <input name="comments" type="radio" id="comments-2" value="0" checked="checked" />
        <?php echo tooltip(_PG_COMMENTS_T);?></span></td>
    </tr>
      <tr>
        <td><?php echo _PG_ACCESS_L;?>:</td>
        <td><?php echo $member->getAccessList();?></td>
      </tr>
      <tr id="memrow">
        <td><?php echo _PG_MEM_LEVEL;?>:</td>
        <td id="membership">
		<?php echo $member->getMembersipList();?>
        </td>
      </tr>
    <tr>
      <td><?php echo _PG_KEYS;?>:</td>
      <td><input name="keywords<?php echo $core->dblang;?>" type="text" class="inputbox" size="80" />
        &nbsp;&nbsp; <?php echo tooltip(_PG_KEYS_T);?></td>
    </tr>
    <tr>
      <td><?php echo _PG_DESC;?>:</td>
      <td><textarea name="description<?php echo $core->dblang;?>" cols="55" rows="6"></textarea></td>
    </tr>
    <tr>
      <td><input type="submit" name="submit" class="button" value="<?php echo _PG_ADD;?>" /></td>
      <td><a href="loader.php?do=pages" class="button-alt"><?php echo _CANCEL;?></a></td>
    </tr>
  </table>
</form>
<script type="text/javascript"> 
// <![CDATA[
$(document).ready(function() {
    $('#memrow').hide();
    $('#access_id').change(function() {
        var option = $(this).val();
        var result = 'pageid=<?php echo $content->pageid;?>';
        result += '&membershiplist=' + option;
		  $.ajax({
			  type: "post",
			  url: "ajax.php",
			  data: result,
			  cache: false,
			  success: function (res) {
				  (option == "Membership") ? $('#memrow').show(): $('#memrow').hide();
				  $('#membership').html(res);
			  }
		  });
    });
});
// ]]>
</script>
<?php echo $core->doForm("processPage");?>
<?php break;?>
<?php default: ?>
<h1><img src="images/pages-sml.png" alt="" /><?php echo _PG_TITLE3;?></h1>
<p class="info"><span><?php echo $core->langIcon();?></span><?php echo _PG_INFO3;?></p>
<h2><span><a href="loader.php?do=pages&amp;action=add" class="button-sml"><?php echo _PG_ADD;?></a></span><?php echo _PG_SUBTITLE3;?></h2>
<table cellpadding="0" cellspacing="0" class="display">
  <thead>
    <tr>
      <th width="20" class="left">#</th>
      <th class="left"><?php echo _PG_TITLE;?></th>
      <th><?php echo _PG_HOME;?></th>
      <th><?php echo _PG_ISCC;?></th>
      <th><?php echo _PUBLISHED;?></th>
      <th><?php echo _PG_EDIT;?></th>
      <th><?php echo _PG_VIEW_P;?></th>
      <th><?php echo _PG_NEW_P;?></th>
      <th><?php echo _DELETE;?></th>
    </tr>
  </thead>
  <tbody>
    <?php if(!$content->getPages()):?>
    <tr>
      <td colspan="10"><?php echo $core->msgAlert(_PG_NOPAGES,false);?></td>
    </tr>
    <?php else:?>
    <?php $home = getValue("page_id", "menus", "home_page = 1");?>
    <?php foreach ($content->getPages() as $row):?>
    <?php $ishome = ($home['home_page'] == $row['id']) ? true : false;?>
    <tr>
      <td><?php echo $row['id'];?>.</td>
      <td><?php echo $row['title'.$core->dblang];?></td>
      <td align="center"><?php echo ($ishome) ? '<img src="images/home.png" alt="" class="tooltip" title="'._PG_HOME.'"/>' : '' ;?></td>
      <td align="center"><?php echo ($row['contact_form'] == 1) ? '<img src="images/mail.png" class="tooltip"  alt="" title="'._PG_ISCCPAGE.'"/>' : '' ;?></td>
      <td align="center"><?php echo isActive($row['active']);?></td>
      <td align="center"><a href="loader.php?do=pages&amp;action=edit&amp;pageid=<?php echo $row['id'];?>"><img src="images/edit.png" class="tooltip"  alt="" title="<?php echo _PG_EDIT;?>"/></a></td>
      <td align="center"><a href="loader.php?do=posts&amp;action=view&amp;pageid=<?php echo $row['id'];?>"><img src="images/search.png" class="tooltip"  alt="" title="<?php echo _PG_VIEW_P;?>"/></a></td>
      <td align="center"><a href="loader.php?do=posts&amp;action=add&amp;pageid=<?php echo $row['id'];?>"><img src="images/add.png" class="tooltip"  alt="" title="<?php echo _PG_NEW_P;?>"/></a></td>
      <td align="center"><a href="javascript:void(0);" class="delete" rel="<?php echo $row['title'];?>" id="item_<?php echo $row['id'];?>"><img src="images/delete.png" class="tooltip"  alt="" title="<?php echo _DELETE;?>"/></a></td>
    </tr>
    <?php endforeach;?>
    <?php unset($row);?>
    <?php endif;?>
  </tbody>
</table>
<div id="dialog-confirm" style="display:none;" title="<?php echo _DELETE.' '._PAGE;?>">
  <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo _DEL_CONFIRM;?></p>
</div>
<script type="text/javascript"> 
// <![CDATA[
$(document).ready(function () {
    $('a.delete').live('click', function () {
        var id = $(this).attr('id').replace('item_', '')
        var parent = $(this).parent().parent();
		var title = $(this).attr('rel');
        $("#dialog-confirm").data({
            'delid': id,
            'parent': parent,
			'title': title
        }).dialog('open');
        return false;
    });

    $("#dialog-confirm").dialog({
        resizable: false,
        bgiframe: true,
        autoOpen: false,
        width: 400,
        height: "auto",
        zindex: 9998,
        modal: false,
        buttons: {
            '<?php echo _DELETE;?>': function () {
                var parent = $(this).data('parent');
                var id = $(this).data('delid');
				var title = $(this).data('title');

                $.ajax({
                    type: 'post',
                    url: "ajax.php",
                    data: 'deletePage=' + id + '&pagetitle=' + title,
                    beforeSend: function () {
                        parent.animate({
                            'backgroundColor': '#FFBFBF'
                        }, 400);
                    },
                    success: function (msg) {
                        parent.fadeOut(400, function () {
                            parent.remove();
                        });
						$("html, body").animate({scrollTop:0}, 600);
						$("#msgholder").html(msg);
                    }
                });

                $(this).dialog('close');
            },
            '<?php echo _CANCEL;?>': function () {
                $(this).dialog('close');
            }
        }
    });
});
// ]]>
</script>
<?php break;?>
<?php endswitch;?>