Adding visibility for promotions and careers + adding bread crumbs

skala
Julio Montoya 14 years ago
parent 02c308043b
commit 2fe03c13a5
  1. 1
      main/admin/career_dashboard.php
  2. 65
      main/admin/careers.php
  3. 63
      main/admin/promotions.php
  4. 61
      main/inc/lib/career.lib.php
  5. 3
      main/inc/lib/database.lib.php
  6. 49
      main/inc/lib/model.lib.php
  7. 62
      main/inc/lib/promotion.lib.php
  8. 3
      main/inc/lib/usergroup.lib.php
  9. 4
      main/install/db_main.sql
  10. 4
      main/install/migrate-db-1.8.7-1.8.8-pre.sql

@ -26,6 +26,7 @@ $htmlHeadXtra[] = api_get_jqgrid_js();
// setting breadcrumbs
$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
$interbreadcrumb[]=array('url' => 'career_dashboard.php','name' => get_lang('CareersAndPromotions'));
Display :: display_header($nameTools);

@ -23,6 +23,8 @@ $htmlHeadXtra[] = api_get_jqgrid_js();
// setting breadcrumbs
$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
$interbreadcrumb[]=array('url' => 'career_dashboard.php','name' => get_lang('CareersAndPromotions'));
$interbreadcrumb[]=array('url' => 'careers.php','name' => get_lang('Careers'));
// The header.
Display::display_header($tool_name);
@ -46,7 +48,8 @@ $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_careers';
$columns = array(get_lang('Name'),get_lang('Description'),get_lang('Actions'));
//Column config
$column_model = array(array('name'=>'name', 'index'=>'name', 'width'=>'80', 'align'=>'left'),
$column_model = array(
array('name'=>'name', 'index'=>'name', 'width'=>'80', 'align'=>'left'),
array('name'=>'description', 'index'=>'description', 'width'=>'500', 'align'=>'left'),
array('name'=>'actions', 'index'=>'actions', 'formatter'=>'action_formatter','width'=>'100', 'align'=>'left'),
);
@ -55,7 +58,7 @@ $extra_params['autowidth'] = 'true';
//height auto
$extra_params['height'] = 'auto';
//With this function we can add actions to the jgrid
//With this function we can add actions to the jgrid (edit, delete, etc)
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
return \'<a href="?action=edit&id=\'+options.rowId+\'"><img src="../img/edit.gif" title="'.get_lang('Edit').'"></a> <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'"><img title="'.get_lang('Delete').'" src="../img/delete.gif"></a>\';
}';
@ -67,40 +70,30 @@ $(function() {
echo Display::grid_js('careers', $url,$columns,$column_model,$extra_params, array(), $action_links);
?>
});
</script>
</script>
<?php
// Tool introduction
Display::display_introduction_section(get_lang('Careers'));
$career = new Career();
// Action handling: Adding a note
// Action handling: Add
if (isset($_GET['action']) && $_GET['action'] == 'add') {
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
api_not_allowed();
}
$_SESSION['notebook_view'] = 'creation_date';
//@todo move this in the career.lib.php
// Initiate the object
$form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
// Settting the form elements
$form->addElement('header', '', get_lang('Add'));
$form->addElement('text', 'name', get_lang('name'), array('size' => '95', 'id' => 'name'));
//$form->applyFilter('note_title', 'html_filter');
$form->addElement('html_editor', 'description', get_lang('Description'), null);
$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
// Setting the rules
$form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
$form = $career->return_form($url, get_lang('Add'));
// The validation or display
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
$res = $career->save($values);
$res = $career->save($values);
if ($res) {
Display::display_confirmation_message(get_lang('Added'));
}
@ -116,30 +109,22 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
$form->setConstants(array('sec_token' => $token));
$form->display();
}
}// Action handling: Editing a note
elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
// Initialize the object
$form = new FormValidator('career', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id']));
// Settting the form elements
$form->addElement('header', '', get_lang('Modify'));
$form->addElement('hidden', 'id',intval($_GET['id']));
$form->addElement('text', 'name', get_lang('Name'), array('size' => '100'));
$form->addElement('html_editor', 'description', get_lang('description'), null);
$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
// Setting the defaults
$defaults = $career->get($_GET['id']);
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
} elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
// Action handling: Editing
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
$form = $career->return_form($url, get_lang('Modify'));
// The validation or display
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
$res = $career->update($values);
$values = $form->exportValues();
$career->update_all_promotion_status_by_career_id($values['id'],$values['status']);
$res = $career->update($values);
if ($res) {
Display::display_confirmation_message(get_lang('Updated'));
}
@ -155,10 +140,9 @@ elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET[
$form->setConstants(array('sec_token' => $token));
$form->display();
}
}
// Action handling: deleting a note
elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
$res = $career->delete(Security::remove_XSS($_GET['id']));
} elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
// Action handling: delete
$res = $career->delete(intval($_GET['id']));
if ($res) {
Display::display_confirmation_message(get_lang('Deleted'));
}
@ -166,5 +150,4 @@ elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GE
} else {
$career->display();
}
Display :: display_footer();

@ -22,6 +22,8 @@ api_protect_admin_script();
$htmlHeadXtra[] = api_get_jqgrid_js();
// setting breadcrumbs
$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
$interbreadcrumb[]=array('url' => 'career_dashboard.php','name' => get_lang('CareersAndPromotions'));
$interbreadcrumb[]=array('url' => 'promotions.php','name' => get_lang('Promotions'));
// The header.
Display::display_header($tool_name);
@ -73,25 +75,8 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
api_not_allowed();
}
// Initiate the object
$form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
// Settting the form elements
$form->addElement('header', '', get_lang('Add'));
$form->addElement('text', 'name', get_lang('name'), array('size' => '95', 'id' => 'name'));
$career = new Career();
$careers = $career->get_all();
$career_list = array();
foreach($careers as $item) {
$career_list[$item['id']] = $item['name'];
}
$form->addElement('select', 'career_id', get_lang('Career'), $career_list);
$form->addElement('html_editor', 'description', get_lang('Description'), null);
$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
// Setting the rules
$form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
$form = $promotion->return_form($url,get_lang('Add'));
// The validation or display
if ($form->validate()) {
@ -114,40 +99,18 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
$form->setConstants(array('sec_token' => $token));
$form->display();
}
}// Action handling: Editing a note
elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
} elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
//Editing
// Initialize the object
//@todo this form should be generated in the class
$form = new FormValidator('promotion', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']));
// Settting the form elements
$form->addElement('header', '', get_lang('Modify'));
$form->addElement('hidden', 'id',intval($_GET['id']));
$form->addElement('text', 'name', get_lang('Name'), array('size' => '100'));
$form->addElement('html_editor', 'description', get_lang('description'), null);
$career = new Career();
$careers = $career->get_all();
$career_list = array();
foreach($careers as $item) {
$career_list[$item['id']] = $item['name'];
}
$form->addElement('select', 'career_id', get_lang('Career'), $career_list);
$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
// Setting the defaults
$defaults = $promotion->get($_GET['id']);
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
$form = $promotion->return_form($url, get_lang('Modify'));
// The validation or display
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
$res = $promotion->update($values);
$res = $promotion->update($values);
if ($res) {
Display::display_confirmation_message(get_lang('Updated'));
}
@ -163,10 +126,8 @@ elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET[
$form->setConstants(array('sec_token' => $token));
$form->display();
}
}
// Action handling: deleting a note
elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
} elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
// Action handling: deleting an obj
$res = $promotion->delete($_GET['id']);
if ($res) {
Display::display_confirmation_message(get_lang('Deleted'));
@ -175,4 +136,4 @@ elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GE
} else {
$promotion->display();
}
Display::display_footer();
Display::display_footer();

@ -8,25 +8,80 @@
*/
require_once 'model.lib.php';
require_once 'promotion.lib.php';
define ('CAREER_STATUS_ACTIVE', 1);
define ('CAREER_STATUS_INACTIVE',0);
class Career extends Model {
var $table;
var $columns = array('id', 'name','description');
var $columns = array('id', 'name','description','status');
public function __construct() {
$this->table = Database::get_main_table(TABLE_CAREER);
}
public function get_all() {
return Database::select('*',$this->table, array('order' =>'name ASC'));
}
public function update_all_promotion_status_by_career_id($career_id, $status) {
$promotion = new Promotion();
$promotion_list = $promotion->get_all_promotions_by_career_id($career_id);
if (!empty($promotion_list)) {
foreach($promotion_list as $item) {
$params['id'] = $item['id'];
$params['status'] = $status;
$promotion->update($params);
}
}
}
/**
* Displays the title + grid
*/
function display() {
public function display() {
// action links
echo '<div class="actions" style="margin-bottom:20px">';
echo '<a href="career_dashboard.php">'.Display::return_icon('back.png',get_lang('Back')).get_lang('Back').'</a>';
echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('filenew.gif',get_lang('Add')).get_lang('Add').'</a>';
echo '</div>';
echo Display::grid_html('careers');
}
}
public function get_status_list() {
return array(CAREER_STATUS_ACTIVE => get_lang('Active'), CAREER_STATUS_INACTIVE => get_lang('Inactive'));
}
/**
* Returns a Form validator Obj
* @todo the form should be auto generated
* @param string url
* @param string header name
* @return obj form validator obj
*/
public function return_form($url, $header) {
$form = new FormValidator('career', 'post', $url);
// Settting the form elements
$form->addElement('header', '', $header);
$form->addElement('hidden', 'id',intval($_GET['id']));
$form->addElement('text', 'name', get_lang('Name'), array('size' => '100'));
$form->addElement('html_editor', 'description', get_lang('description'), null);
$status_list = $this->get_status_list();
$form->addElement('select', 'status', get_lang('Status'), $status_list);
$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
// Setting the defaults
$defaults = $this->get($_GET['id']);
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
return $form;
}
}

@ -1487,7 +1487,8 @@ class Database {
if (!empty($update_sql)) {
//Parsing and cleaning the where conditions
$where_return = self::parse_where_conditions($where_conditions);
$sql = "UPDATE $table_name SET $update_sql $where_return ";
$sql = "UPDATE $table_name SET $update_sql $where_return ";
//echo $sql; exit;
$result = self::query($sql);
$affected_rows = self::affected_rows();
return $affected_rows;

@ -12,8 +12,7 @@ class Model {
var $table;
var $columns;
public function __construct() {
public function __construct() {
}
public function find() {
@ -24,7 +23,7 @@ class Model {
/**
* Delets an item
*/
function delete($id) {
public function delete($id) {
if (empty($id) or $id != strval(intval($id))) { return false; }
// Database table definition
$result = Database :: delete($this->table, array('id = ?' => $id));
@ -49,7 +48,7 @@ class Model {
/**
* Displays the title + grid
*/
function display() {
public function display() {
}
@ -57,20 +56,20 @@ class Model {
/**
* Gets an element
*/
function get($id) {
public function get($id) {
if (empty($id)) { return array(); }
$result = Database::select('*',$this->table, array('where'=>array('id = ?'=>intval($id))),'first');
return $result;
}
function get_all() {
return $careers = Database::select('*',$this->table);
public function get_all() {
return Database::select('*',$this->table);
}
/**
* Get the count of elements
*/
function get_count() {
public function get_count() {
$row = Database::select('count(*) as count', $this->table, array(),'first');
return $row['count'];
}
@ -81,7 +80,7 @@ class Model {
* @return unknown
*
*/
function javascript() {
public function javascript() {
}
@ -92,10 +91,10 @@ class Model {
* @return bool
*
*/
function save($values) {
$values = $this->clean_parameters($values);
if (!empty($values)) {
$id = Database::insert($this->table, $values);
public function save($params) {
$params = $this->clean_parameters($params);
if (!empty($params)) {
$id = Database::insert($this->table, $params);
if (is_numeric($id)){
return $id;
}
@ -104,23 +103,23 @@ class Model {
}
/**
* Updates the obj in the database
* Updates the obj in the database. The $params['id'] must exist in order to update a record
*
* @param array $values
*
*/
function update($values) {
$values = $this->clean_parameters($values);
if (!empty($values)) {
$id = $values['id'];
unset($values['id']);
$result = Database::update($this->table, $values, array('id = ?'=>$id));
if ($result){
return true;
}
public function update($params) {
$params = $this->clean_parameters($params);
if (!empty($params)) {
$id = $params['id'];
unset($params['id']); //To not overwrite the id
if (is_numeric($id)) {
$result = Database::update($this->table, $params, array('id = ?'=>$id));
if ($result){
return true;
}
}
}
return false;
}
}

@ -8,24 +8,36 @@
*/
require_once 'model.lib.php';
require_once 'career.lib.php';
define ('PROMOTION_STATUS_ACTIVE', 1);
define ('PROMOTION_STATUS_INACTIVE',0);
class Promotion extends Model {
var $table;
var $columns = array('id','name','description','career_id');
var $columns = array('id','name','description','career_id','status');
public function __construct() {
$this->table = Database::get_main_table(TABLE_PROMOTION);
}
function get_all_promotions_by_career_id($career_id) {
/**
* Gets all promotions by career id
* @param int career id
* @return array results
*/
public function get_all_promotions_by_career_id($career_id) {
return Database::select('*', $this->table, array('where'=>array('career_id = ?'=>$career_id)));
}
}
public function get_status_list() {
return array(PROMOTION_STATUS_ACTIVE => get_lang('Active'), PROMOTION_STATUS_INACTIVE => get_lang('Inactive'));
}
/**
* Displays the title + grid
* @return string html code
*/
function display() {
// action links
@ -36,5 +48,45 @@ class Promotion extends Model {
echo Display::grid_html('promotions');
}
/**
* Returns a Form validator Obj
* @todo the form should be auto generated
* @param string url
* @param string header name
* @return obj form validator obj
*/
function return_form($url, $header) {
$form = new FormValidator('promotion', 'post', $url);
// Settting the form elements
$form->addElement('header', '', $header);
$form->addElement('hidden', 'id', intval($_GET['id']));
$form->addElement('text', 'name', get_lang('Name'), array('size' => '100','id' => 'name'));
$form->addElement('html_editor', 'description', get_lang('description'), null);
$career = new Career();
$careers = $career->get_all();
$career_list = array();
foreach($careers as $item) {
$career_list[$item['id']] = $item['name'];
}
$form->addElement('select', 'career_id', get_lang('Career'), $career_list);
$status_list = $this->get_status_list();
$form->addElement('select', 'status', get_lang('Status'), $status_list);
$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
// Setting the defaults
$defaults = $this->get($_GET['id']);
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
return $form;
}
}

@ -79,8 +79,7 @@ class UserGroup extends Model {
}
}
return $array;
}
}
/**

@ -2544,6 +2544,7 @@ CREATE TABLE career (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL ,
description TEXT NOT NULL,
status INT NOT NULL default '0',
PRIMARY KEY (id)
);
@ -2552,6 +2553,7 @@ CREATE TABLE promotion (
name VARCHAR(255) NOT NULL ,
description TEXT NOT NULL,
career_id INT NOT NULL,
status INT NOT NULL default '0',
PRIMARY KEY(id)
);
@ -2560,7 +2562,7 @@ CREATE TABLE usergroup (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
PRIMARY KEY (id)
PRIMARY KEY (id)
);
CREATE TABLE usergroup_rel_user (

@ -174,8 +174,8 @@ INSERT INTO course_setting(variable,value,category) VALUES ('enable_lp_auto_laun
INSERT INTO course_setting(variable,value,category) VALUES ('pdf_export_watermark_text','','course');
CREATE TABLE career (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, description TEXT NOT NULL,PRIMARY KEY (id));
CREATE TABLE promotion (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, description TEXT NOT NULL, career_id INT NOT NULL,PRIMARY KEY(id));
CREATE TABLE career (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, description TEXT NOT NULL, status INT NOT NULL default '0' PRIMARY KEY (id));
CREATE TABLE promotion (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, description TEXT NOT NULL, status INT NOT NULL default '0', career_id INT NOT NULL,PRIMARY KEY(id));
ALTER TABLE session ADD promotion_id INT NOT NULL;
CREATE TABLE usergroup ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, description TEXT NOT NULL,PRIMARY KEY (id));

Loading…
Cancel
Save