Skip to content

Commit

Permalink
Changing the behaviour of the page class. Now we separate the page::c…
Browse files Browse the repository at this point in the history
…ontent function in different process: page::add, page::edit, page::delete, page::listing inspired in Akelos framework. This is an experimental change wroking only in the Billing cycle page. Fixing also some Billing template names.
  • Loading branch information
jmontoyaa committed Aug 26, 2010
1 parent b179649 commit ad56dcc
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 100 deletions.
54 changes: 49 additions & 5 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@
//THT Variables
define("PAGE", "Admin Area");

/**
*
* @todo Important TODO message
*
*
* This acp function should be change so everytime we do a called URL like this:
*
* ?page=servers&sub=show&do=1
*
* the page::show() function should be called
*
* Then we can add some url friendly changes so we should load this page: *
* server/show/1 when in fact we are loading the page=servers&sub=show&do=1 URL
*
* That means changing everything in the page class and while loading every controller
*
* example
* page::add
* page::show
* page::update
* page::delete
* page::list
*
* This will be more like Akelos controller class see the example I did with the Billing Cycle page:
* admin/pages/billing.php,
* includes/class_billing.php
* includes/tpl/billing
*
*
* */

//Main ACP Function - Creates the ACP basically
function acp() {
global $main, $db, $style, $type, $email, $user;
Expand Down Expand Up @@ -84,8 +115,7 @@ function acp() {
}
}
}
}
}
$array2['IMGURL'] = "logout.png";
$array2['LINK'] = "?page=logout";
$array2['VISUAL'] = "Logout";
Expand Down Expand Up @@ -127,8 +157,7 @@ function acp() {
}
}
}
}

}

if($main->getvar['sub'] == 'delete' && isset($main->getvar['do']) && !$_POST && !$main->getvar['confirm']) {
foreach($main->postvar as $key => $value) {
Expand All @@ -155,7 +184,22 @@ function acp() {
} else {
if(isset($main->getvar['sub'])) {
ob_start();
$content->content();

/**
* Experimental changes only applied to the billing cycle objects otherwise work as usual
* */
if (isset($content->pagename) && $content->pagename == 'billing') {
$method_list = array('add', 'edit', 'delete', 'show', 'listing');
$sub = $main->getvar['sub'];
if(in_array($sub, $method_list)) {
$content->$sub();
} else {
$content->listing();
}
} else {
$content->content();
}

$html = ob_get_contents(); # Retrieve the HTML
ob_clean(); # Flush the HTML
} elseif($content->navlist) {
Expand Down
196 changes: 109 additions & 87 deletions admin/pages/billing.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
/* For licensing terms, see /license.txt */

/**
*
/**
* @author Julio Montoya <[email protected]> BeezNest 2010
*/

Expand All @@ -15,22 +14,64 @@ class page {

public function __construct() {
$this->navtitle = "Billing Sub Menu";

$this->navlist[] = array("View All Billing cycles", "package_add.png", "view");
$this->navlist[] = array("Add Billing cycle", "add.png", "add");

$this->pagename = 'billing';
$this->navlist[] = array("List All Billing cycles", "package_add.png", "listing");
$this->navlist[] = array("Add Billing cycle", "add.png", "add");
}

public function description() {
return "<strong>Managing Billing cycles</strong><br />
Welcome to the Package Management Area. Here you can add, edit and delete web hosting packages. Have fun :)<br />
To get started, choose a link from the sidebar's SubMenu.";
}

public function add() {
global $main, $style, $billing;

if($_POST && $main->checkToken()) {
foreach($main->postvar as $key => $value) {
if($value == "" && !$n && $key != "admin") {
$main->errors("Please fill in all the fields!");
$n++;
}
}
if(!$n) {
foreach($main->postvar as $key => $value) {
if($key != "name" && $key != "number_months") {
if($n) {
$additional .= ",";
}
$additional .= $key."=".$value;
$n++;
}
}

if ($main->postvar['status'] == 'on') {
$main->postvar['status'] = BILLING_CYCLE_STATUS_ACTIVE;
} else {
$main->postvar['status'] = BILLING_CYCLE_STATUS_INACTIVE;
}
$billing->create($main->postvar);
$main->errors("Billing cycle has been added!");
$main->redirect('?page=billing&sub=listing&msg=1');
}
}

for($i = 1; $i<=MAX_NUMBER_MONTHS; $i++) {
$values[] = array($i,$i);
}
$array['NUMBER_MONTHS'] = $main->dropDown("number_months", $values, '');
$array['STATUS'] = $main->createCheckbox('', 'status');
echo $style->replaceVar("tpl/billing/add.tpl", $array);
}

public function content() { # Displays the page
public function edit() {
global $main, $style, $db, $billing;
switch($main->getvar['sub']) {
default:
if(isset($main->getvar['do'])) {
$query = $db->query("SELECT * FROM `<PRE>billing_cycles` WHERE `id` = '{$main->getvar['do']}'");
if($db->num_rows($query) == 0) {
echo "That billing cycle doesn't exist!";
} else {
if($_POST && $main->checkToken()) {
foreach($main->postvar as $key => $value) {
if($value == "" && !$n && $key != "admin") {
Expand All @@ -48,93 +89,74 @@ public function content() { # Displays the page
$n++;
}
}

if ($main->postvar['status'] == 'on') {
$main->postvar['status'] = BILLING_CYCLE_STATUS_ACTIVE;
} else {
$main->postvar['status'] = BILLING_CYCLE_STATUS_INACTIVE;
}
$billing->create($main->postvar);
$main->errors("Biiling cycle has been added!");
$main->redirect('?page=billing&sub=edit&msg=1');
}
}
$billing->edit($main->getvar['do'],$main->postvar);
$main->errors('Billing cycle has been edited!');
$main->redirect('?page=billing&sub=listing&msg=1');
}
}

$data = $db->fetch_array($query);
$array['ID'] = $data['id'];
$array['NAME'] = $data['name'];

for($i = 1; $i<=MAX_NUMBER_MONTHS; $i++) {
$values[] = array($i,$i);
}
$array['NUMBER_MONTHS'] = $main->dropDown("number_months", $values, '');
$array['STATUS'] = $main->createCheckbox('', 'status');
echo $style->replaceVar("tpl/billing/addbillingcycle.tpl", $array);
break;
case 'view':
case 'edit':
if(isset($main->getvar['do'])) {
$query = $db->query("SELECT * FROM `<PRE>billing_cycles` WHERE `id` = '{$main->getvar['do']}'");
if($db->num_rows($query) == 0) {
echo "That billing cycle doesn't exist!";
} else {
if($_POST && $main->checkToken()) {
foreach($main->postvar as $key => $value) {
if($value == "" && !$n && $key != "admin") {
$main->errors("Please fill in all the fields!");
$n++;
}
}
if(!$n) {
foreach($main->postvar as $key => $value) {
if($key != "name" && $key != "number_months") {
if($n) {
$additional .= ",";
}
$additional .= $key."=".$value;
$n++;
}
}
if ($main->postvar['status'] == 'on') {
$main->postvar['status'] = BILLING_CYCLE_STATUS_ACTIVE;
} else {
$main->postvar['status'] = BILLING_CYCLE_STATUS_INACTIVE;
}
$billing->edit($main->getvar['do'],$main->postvar);
$main->errors('Billing cycle has been edited!');
$main->redirect('?page=billing&sub=edit&msg=1');
}
}

$data = $db->fetch_array($query);
$array['ID'] = $data['id'];
$array['NAME'] = $data['name'];

for($i = 1; $i<=MAX_NUMBER_MONTHS; $i++) {
$values[] = array($i,$i);
}
$array['NUMBER_MONTHS'] = $main->dropDown("number_months", $values, $data['number_months']);
$array['STATUS'] = $main->createCheckbox('', 'status', $data['status']);

echo $style->replaceVar("tpl/billing/editbillingcycles.tpl", $array);
}
} else {
$query = $db->query("SELECT * FROM `<PRE>billing_cycles`");
if($db->num_rows($query) == 0) {
echo "There are no billing cycles to edit!";
} else {
echo "<ERRORS>";
while($data = $db->fetch_array($query)) {
echo $main->sub("<strong>".$data['name']."</strong>", '<a href="?page=billing&sub=edit&do='.$data['id'].'"><img src="'. URL .'themes/icons/pencil.png"></a>&nbsp;<a href="?page=billing&sub=delete&do='.$data['id'].'"><img src="'. URL .'themes/icons/delete.png"></a>');
$n++;
}
}
}
break;
case 'delete':
if($main->getvar['do'] && $main->checkToken()) {
$billing->setId($main->getvar['do']);
$billing->delete();
$main->errors("Billing cycle #{$main->getvar['do']} has been deleted!");
$main->redirect('?page=billing&sub=edit&msg=1');
}
break;
$array['NUMBER_MONTHS'] = $main->dropDown("number_months", $values, $data['number_months']);
$array['STATUS'] = $main->createCheckbox('', 'status', $data['status']);

echo $style->replaceVar("tpl/billing/edit.tpl", $array);

}
}
}

public function delete() {
global $main, $billing;
if($main->getvar['do'] && $main->checkToken()) {
$billing->setId($main->getvar['do']);
$billing->delete();
$main->errors("Billing cycle #{$main->getvar['do']} has been deleted!");
$main->redirect('?page=billing&sub=listing&msg=1');
}
}

/**
* Experimental changes
*
* */
public function listing() {
global $main, $style, $db, $billing;
$query = $db->query("SELECT * FROM `<PRE>billing_cycles`");
if($db->num_rows($query) == 0) {
echo "There are no billing cycles to edit!";
} else {
echo "<ERRORS>";
while($data = $db->fetch_array($query)) {
echo $main->sub('<strong><a href="?page=billing&sub=show&do='.$data['id'].'">'.$data['name']."</a></strong>", '<a href="?page=billing&sub=edit&do='.$data['id'].'"><img src="'. URL .'themes/icons/pencil.png"></a>&nbsp;<a href="?page=billing&sub=delete&do='.$data['id'].'"><img src="'. URL .'themes/icons/delete.png"></a>');

}
}
}

public function show() {
global $style, $main, $billing;
if ($main->getvar['do']) {
$result = $billing->find($main->getvar['do']);
$array['id'] = $result->id;
$array['number_months'] = $result->number_months;
$array['name'] = $result->name;
$array['status'] = ($result->status)? 'Active': 'Inactive';
echo $style->replaceVar("tpl/billing/show.tpl", $array);
}
}

public function content() { # Displays the page
//default page
}
}
11 changes: 9 additions & 2 deletions documentation/credits.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ <h1>Core developers</h1>
<li>Julio Allen Montoya Armas ([email protected]) - Lead developer</li>
</ul>
</li>

<li>Independant</li>
<ul>
<li>ispcomm (Paolo) - Client Company changes</li>
</ul>
</li>

<li>THT (2008-2009) </li>
<ul>
<li>Jonny [email protected]</li>
Expand All @@ -32,12 +39,12 @@ <h1>Core developers</h1>
<li>KuJoe [email protected]</li>
<li>Matt [email protected]</li>
</ul>
</li>
</li>
</ol>

<hr />
<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" style="margin: 1em; float: right;" height="31" width="88" /></a>
<a href="http://jigsaw.w3.org/css-validator/">
<img src="http://jigsaw.w3.org/css-validator/images/vcss-blue" style="margin: 1em; float: right;" alt="Valid CSS" />
</a>
</body></html>
</body></html>
1 change: 1 addition & 0 deletions includes/class_billing.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class billing extends model {

public $columns = array('id', 'number_months','name', 'status');
public $table_name = 'billing_cycles';
public $_modelName = 'billing';

// products = addons or packages
public $has_many = array('products'=> array('table_name'=>'billing_products', 'columns'=>array('billing_id', 'product_id', 'amount','type')));
Expand Down
12 changes: 6 additions & 6 deletions includes/javascript/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ function onlyNumbers(evt)
}

function tblshowhide(id, imgid, url) {

if(document.getElementById(id).style.display == "none") {
$("#"+id).slideDown(500, function() {
$("#"+id).slideDown(200, function() {
document.getElementById(imgid).src = url+"themes/icons/bullet_toggle_minus.png";
});
}
else {
$("#"+id).slideUp(500, function() {
});
} else {
$("#"+id).slideUp(200, function() {
document.getElementById(imgid).src = url+"themes/icons/bullet_toggle_plus.png";
});
});
}
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ad56dcc

Please sign in to comment.