   <?php
   require_once("whm.class.php");
   
   // CRUD 
   @$getId = base64_decode(anti_injection($_GET['id']));  
    if(@$getId){ 
        $query = mysql_query("SELECT * FROM packages WHERE id = + $getId");
        $result = mysql_fetch_array($query);
        
    }
    
    if(isset ($_POST['save'])){
	$idserver = $_POST['server'];
	$name = $_POST['name'];
	$quota = $_POST['quota'];
	$bandwidth = $_POST['bandwidth'];
	$subdomain = $_POST['subdomain'];
	$park = $_POST['park'];
	$addon = $_POST['addon'];
	$ftp = $_POST['ftp'];
	$pop = $_POST['pop'];
	$list = $_POST['list'];
	$sql = $_POST['sql'];
	$feature = $_POST['feature'];
	$ip = $_POST['ip'];
	$cgi = $_POST['cgi'];
	$fronpage = $_POST['fronpage'];
	$lang = $_POST['lang'];
	$theme = $_POST['theme'];
	
	$query = mysql_query("SELECT * FROM servers WHERE id = '$idserver'");
	$srv = mysql_fetch_array($query);
	$namepack = $srv['user'] . "_" . $name;

	$crud = new crud('packages');  // table
    $crud->inserir("server,name,quota,bandwidth,subdomain,park,addon,ftp,pop,list,psql,feature,ip,cgi,fronpage,lang,theme", "'$idserver','$namepack','$quota','$bandwidth','$subdomain','$park','$addon','$ftp','$pop','$list','$sql','$feature','$ip','$cgi','$fronpage','$lang','$theme'");
	
	$whmdomain = $srv['domain'];
	$whmuser = $srv['user'];
	$whmpwd = $srv['pwd'];
	$WHM = new WHM( false , $whmdomain, $whmuser, $whmpwd);
	$packages = $WHM->add_package($namepack,$quota,$bandwidth,$subdomain,$park,$addon,$ftp,$pop,$list,$sql,$ip,$lang,$theme);
	
	header("Location: index.php?mod=Packages&y=1"); // redirect send mail ok
    
	
	}
	
	if(isset($_POST['update'])) {
	$idserver = $_POST['server'];
	$name = $_POST['packagename'];
	$quota = $_POST['quota'];
	$bandwidth = $_POST['bandwidth'];
	$subdomain = $_POST['subdomain'];
	$park = $_POST['park'];
	$addon = $_POST['addon'];
	$ftp = $_POST['ftp'];
	$pop = $_POST['pop'];
	$list = $_POST['list'];
	$sql = $_POST['sql'];
	$feature = $_POST['feature'];
	$ip = $_POST['ip'];
	$cgi = $_POST['cgi'];
	$fronpage = $_POST['fronpage'];
	$lang = $_POST['lang'];
	$theme = $_POST['theme'];
	
	$registerID = $_POST['registerID'];
	
	$crud = new crud('packages'); // Table
    $crud->atualizar("quota='$quota',bandwidth='$bandwidth',subdomain='$subdomain',park='$park',addon='$addon',ftp='$ftp',pop='$pop',list='$list',psql='$sql',feature='$feature',ip='$ip',cgi='$cgi',fronpage='$fronpage',lang='$lang',theme='$theme'", "id='$registerID'");
	
	$query = mysql_query("SELECT * FROM servers WHERE id = '$idserver'");
	$srv = mysql_fetch_array($query);
	
	$whmdomain = $srv['domain'];
	$whmuser = $srv['user'];
	$whmpwd = $srv['pwd'];
	$WHM = new WHM( false , $whmdomain, $whmuser, $whmpwd);
	$packages = $WHM->edit_package($name,$quota,$bandwidth,$subdomain,$park,$addon,$ftp,$pop,$list,$sql,$ip,$lang,$theme);
	
	header("Location: index.php?mod=Packages&y=2");
	}
	
    if ((isset($_GET["action"])) && ($_GET["action"] == "delete")) {
    $id = base64_decode($_GET['id']); 
    $crud = new crud('packages'); // Table
    $crud->excluir("id = $id"); // ID
    $acct = $_GET['acct'];
    $idserver = $_GET['server'];
    
    $query = mysql_query("SELECT * FROM servers WHERE id = '$idserver'");
	$srv = mysql_fetch_array($query);
	
	$whmdomain = $srv['domain'];
	$whmuser = $srv['user'];
	$whmpwd = $srv['pwd'];
	$WHM = new WHM( false , $whmdomain, $whmuser, $whmpwd);
	$packages = $WHM->delete_package($acct);
	
    header("Location: index.php?mod=Packages&y=3");
    }
    
    
    ?>
   
      
      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            <?php echo $lang['TITLE_NEW_PACKAGE']; ?>
          </h1>
          
        </section>

       
       <!-- Main content -->
        <section class="content">
          <div class="row">
			  
			  
            <!-- left column -->
            <div class="col-md-6">
              <!-- general form elements -->
              <div class="box box-primary">
                <div class="box-header with-border">
                  <h3 class="box-title"><?php echo $lang['PACKAGE']; ?></h3>
                </div><!-- /.box-header -->
                <!-- form start -->
                <form role="form" method="POST" id="CustomerForm" name="CustomerForm">
				<input type="hidden" name="len" id="pass-len" value="8">
					
             <div class="box-body">
					  
					<?php if (@$result['id'] <> '') { ?><? } else { ?>
                   

					<div class="form-group">
                      <label for="Input"><?php echo $lang['SERVER']; ?></label>
                      <select id="server" name="server" id="server" class="form-control select2" style="width: 100%;" required>
						  <option value="">Select</option>
                    <?php
					$catsr = mysql_query("SELECT * FROM servers order by id DESC");
					while($srv = mysql_fetch_array($catsr)){ 
					?>
                    <option value="<?php echo $srv['id']; ?>" <?php if (@$result['server'] == $srv['id']) { echo "selected"; } ?>><?php echo $srv['server']; ?> - <?php echo $srv['ip']; ?> - <?php echo $srv['module']; ?></option>
				    <?php } ?> 
				    </select>
                    </div>
					  
				
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PACK_NAME']; ?></label>
                      <input type="text" class="form-control" name="name" id="name" value="<?php echo @$result['name']; ?>">
                    </div>
                    <?php } ?>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PACK_QUOTA']; ?></label>
                      <input type="number" min="0" class="form-control" name="quota" id="quota" value="<?php echo @$result['quota']; ?>">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PACK_BAND']; ?></label>
                      <input type="number" min="0" class="form-control" name="bandwidth" id="bandwidth" value="<?php echo @$result['bandwidth']; ?>">
                    </div>
                    
				    <div class="form-group">
                      <label for="Input"><?php echo $lang['PACK_SUB']; ?></label>
                      <input type="number" min="0" class="form-control" name="subdomain" id="subdomain" value="<?php echo @$result['subdomain']; ?>">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PACK_PARK']; ?></label>
                      <input type="number" min="0" class="form-control" name="park" id="park" value="<?php echo @$result['park']; ?>">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PACK_ADDON']; ?></label>
                      <input type="number" min="0" class="form-control" name="addon" id="addon" value="<?php echo @$result['addon']; ?>">
                    </div>
                   
                   
                  </div><!-- /.box-body -->

                 
                
                
              </div><!-- /.box -->
           </div><!-- /.col -->
           
           
           <!-- left column -->
            <div class="col-md-6">
              <!-- general form elements -->
              <div class="box box-info">
                <div class="box-header with-border">
                  <h3 class="box-title"><?php echo $lang['PACKAGE']; ?></h3>
                </div><!-- /.box-header -->
                <!-- form start -->
   
                  <div class="box-body">
					 
					 <div class="form-group">
                      <label for="Input"><?php echo $lang['PACK_FTP']; ?></label>
                      <input type="number" min="0" class="form-control" name="ftp" id="ftp" value="<?php echo @$result['ftp']; ?>">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PACK_POP']; ?></label>
                      <input type="number" min="0" class="form-control" name="pop" id="pop" value="<?php echo @$result['pop']; ?>">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PACK_LIST']; ?></label>
                      <input type="number" min="0" class="form-control" name="list" id="list" value="<?php echo @$result['list']; ?>">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PACK_SQL']; ?></label>
                      <input type="number" min="0" class="form-control" name="sql" id="sql" value="<?php echo @$result['psql']; ?>">
                    </div>
                    
              
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['CATEGORY_NAME']; ?></label>
                   <select name="lang" class="form-control">
                  <option value="en">English</option>
                  <option value="pt_br">Português Brasil</option>
                  <option value="es">Español</option>
                  <option value="it">Italiano</option>
                  <option value="fr">Français</option>
                   </select>
                    </div>
                    
                     <div class="form-group">
                      <label for="Input"><?php echo $lang['THEME']; ?></label>
                       <select name="theme" class="form-control">
                  <option value="x3">x3</option>
                  <option value="x3mail">x3mail</option>
                  <option value="paper_lantern">paper_lantern</option>
                   </select>
                    </div>
                  
                   
                  </div><!-- /.box-body -->

                  <div class="box-footer">
					  
		  <?php if (@$result['id'] <> '') { ?>

		  <input type="submit" value="<?php echo $lang['UPDATE']; ?>" name="update" style="text-transform:uppercase" class="btn btn-info btn-lg btn-block">
		  <input type="hidden" name="registerID" value="<?php echo @$result['id']; ?>"> 
		  <input type="hidden" name="packagename" value="<?php echo @$result['name']; ?>"> 
		  <input type="hidden" name="server" value="<?php echo @$result['server']; ?>"> 
		  <? } else { ?>
		  <input type="submit" value="<?php echo $lang['REGISTER']; ?>" name="save" style="text-transform:uppercase" class="btn btn-success btn-lg btn-block">
		  <?php } ?>
					  
                  </div>
                  
                 
                </form>
                
              </div><!-- /.box -->
           </div><!-- /.col -->
           
          </div><!-- /.row -->
        </section><!-- /.content -->
       
        
      </div><!-- /.content-wrapper -->
   
   
   
   

