$(function() {
<?php 
echo Display::grid_js('promotions', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
?>
});
</script>
<?php 
$promotion = new Promotion();
switch ($action) {
    case 'add':
        if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
            api_not_allowed();
        }
        //First you need to create a Career
        $career = new Career();
        $careers = $career->get_all();
        if (empty($careers)) {
            $url = Display::url(get_lang('YouNeedToCreateACareerFirst'), 'careers.php?action=add');
            Display::display_normal_message($url, false);
            Display::display_footer();
            exit;
        }
        $url = api_get_self() . '?action=' . Security::remove_XSS($_GET['action']);
        $form = $promotion->return_form($url, 'add');
        // The validation or display
        if ($form->validate()) {
            if ($check) {
                $values = $form->exportValues();
                $res = $promotion->save($values);
                if ($res) {
                    Display::display_confirmation_message(get_lang('ItemAdded'));
$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(null);
$form = new FormValidator('filter_form', 'GET', api_get_self());
$career = new Career();
$condition = array('status = ?' => 1);
if ($form->validate()) {
    $data = $form->getSubmitValues();
    $filter = intval($data['filter']);
    if (!empty($filter)) {
        $condition = array('status = ? AND id = ? ' => array(1, $filter));
    }
}
$careers = $career->get_all(array('status = ?' => 1));
//only status =1
$career_select_list = array();
$career_select_list[0] = ' -- ' . get_lang('Select') . ' --';
foreach ($careers as $item) {
    $career_select_list[$item['id']] = $item['name'];
}
$form->addSelect('filter', get_lang('Career'), $career_select_list, array('id' => 'filter_1'));
$form->addButtonSearch(get_lang('Filter'));
// action links
echo '<div class="actions" style="margin-bottom:20px">';
echo '<a href="../admin/index.php">' . Display::return_icon('back.png', get_lang('BackTo') . ' ' . get_lang('PlatformAdmin'), '', ICON_SIZE_MEDIUM) . '</a>';
echo '<a href="careers.php">' . Display::return_icon('career.png', get_lang('Careers'), '', ICON_SIZE_MEDIUM) . '</a>';
echo '<a href="promotions.php">' . Display::return_icon('promotion.png', get_lang('Promotions'), '', ICON_SIZE_MEDIUM) . '</a>';
echo '</div>';
$form->display();
    /**
     * 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, $action = 'add')
    {
		$oFCKeditor = new FCKeditor('description') ;
		$oFCKeditor->ToolbarSet = 'careers';
		$oFCKeditor->Width		= '100%';
		$oFCKeditor->Height		= '200';
		$oFCKeditor->Value		= '';
		$oFCKeditor->CreateHtml();

		$form = new FormValidator('promotion', 'post', $url);
        // Setting the form elements
        $header = get_lang('Add');
        if ($action == 'edit') {
        	$header = get_lang('Modify');
        }
        $id = isset($_GET['id']) ? intval($_GET['id']) : '';

        $form->addElement('header', '', $header);
        $form->addElement('hidden', 'id', $id);
        $form->addElement('text', 'name', get_lang('Name'), array('size' => '70','id' => 'name'));
        $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', 'Height' => '250'));
        $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);
        if ($action == 'edit') {
            $form->addElement('text', 'created_at', get_lang('CreatedAt'));
            $form->freeze('created_at');
        }
      	if ($action == 'edit') {
        	$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
        } else {
        	$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"');
        }

        // Setting the defaults
        $defaults = $this->get($id);
        if (!empty($defaults['created_at'])) {
        	$defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
        }
        if (!empty($defaults['updated_at'])) {
        	$defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
        }
        $form->setDefaults($defaults);

        // Setting the rules
        $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');

        return $form;
    }