public function definition()
 {
     global $CFG, $PAGE, $DB;
     $context = context_system::instance();
     $mform =& $this->_form;
     $strrequired = get_string('required');
     $mform->addElement('hidden', 'templateid', $this->templateid);
     $mform->addElement('hidden', 'templatename', $this->templaterecord->name);
     $mform->addElement('hidden', 'companyid', $this->companyid);
     $company = new company($this->companyid);
     // Then show the fields about where this block appears.
     $mform->addElement('header', 'header', get_string('email_template_send', 'local_email', array('name' => $this->templaterecord->name, 'companyname' => $company->get_name())));
     $mform->addElement('static', 'subject', get_string('subject', 'local_email'));
     $mform->addElement('static', 'body', get_string('body', 'local_email'));
     $mform->addElement('header', 'header', get_string('email_data', 'local_email'));
     $this->addHtml($mform, get_string('company', 'block_iomad_company_admin'), $company->get_name());
     $this->addHtml($mform, get_string('select_course', 'local_email'), $this->currentcourses->display(true));
     $this->add_action_buttons(true, get_string('send_emails', 'local_email'));
 }
    public function definition_after_data()
    {
        $mform =& $this->_form;
        // Adding the elements in the definition_after_data function rather than in the
        // definition function  so that when the currentcourses or potentialcourses get changed
        // in the process function, the changes get displayed, rather than the lists as they
        // are before processing.
        $context = context_system::instance();
        $company = new company($this->selectedcompany);
        $mform->addElement('header', 'header', get_string('company_courses_for', 'block_iomad_company_admin', $company->get_name()));
        /*GWL : Remove Department Dropdown from Manage Companies -> Assign Course */
        /*
        $mform->addElement('select', 'deptid',
                            get_string('department', 'block_iomad_company_admin'),
                            $this->subhierarchieslist);
        $mform->addElement('submit', 'updateselection',
                       get_string('updatedepartmentusersselection', 'block_iomad_company_admin'));
        */
        /*GWL : Remove Department Dropdown from Manage Companies -> Assign Course */
        //if (count($this->potentialcourses->find_courses('')) ||
        //count($this->currentcourses->find_courses(''))) {
        $mform->addElement('html', '<table summary="" class="companycoursetable addremovetable' . ' generaltable generalbox boxaligncenter" cellspacing="0">
                <tr>
                  <td id="existingcell">');
        $mform->addElement('html', $this->currentcourses->display(true));
        $mform->addElement('html', '
                  </td>
                  <td id="buttonscell">
                      <div id="addcontrols">
                          <input name="add" id="add" type="submit" value="&#x25C4;&nbsp;' . get_string('add') . '" title="Add" /><br />

                      </div>

                      <div id="removecontrols">
                          <input name="remove" id="remove" type="submit" value="' . get_string('remove') . '&nbsp;&#x25BA;" title="Remove" />
                      </div>
                  </td>
                  <td id="potentialcell">');
        $mform->addElement('html', $this->potentialcourses->display(true));
        $mform->addElement('html', '
                  </td>
                </tr>
              </table>');
        // Can this user move courses with existing enrollments
        // (which unenrolls those users as a result)?
        if (iomad::has_capability('block/iomad_company_admin:company_course_unenrol', $context)) {
            $mform->addElement('html', get_string('unenrollwarning', 'block_iomad_company_admin'));
            $mform->addElement('checkbox', 'oktounenroll', get_string('oktounenroll', 'block_iomad_company_admin'));
        } else {
            $mform->addElement('html', get_string('unenrollincapable', 'block_iomad_company_admin'));
        }
        //} else {
        //$mform->addElement('html', get_string('nocourses', 'block_iomad_company_admin'));
        //}
    }
    public function definition_after_data()
    {
        global $USER;
        $mform =& $this->_form;
        // Adding the elements in the definition_after_data function rather than in the definition function
        // so that when the currentmanagers or potentialmanagers get changed in the process function, the
        // changes get displayed, rather than the lists as they are before processing.
        $company = new company($this->selectedcompany);
        $managertypes = $company->get_managertypes();
        $mform->addElement('header', 'header', get_string('company_managers_for', 'block_iomad_company_admin', $company->get_name()));
        $mform->addElement('select', 'deptid', get_string('department', 'block_iomad_company_admin'), $this->subhierarchieslist);
        $mform->addHelpButton('deptid', 'department', 'block_iomad_company_admin');
        $mform->addElement('select', 'managertype', get_string('managertype', 'block_iomad_company_admin'), $managertypes);
        $mform->addHelpButton('managertype', 'managertype', 'block_iomad_company_admin');
        if (iomad::has_capability('block/iomad_company_admin:company_add', context_system::instance())) {
            // This user can add other managers to this company.
            $mform->addElement('selectyesno', 'showothermanagers', get_string('showothermanagers', 'block_iomad_company_admin'));
            $mform->disabledIf('showothermanagers', 'managertype', 'neq', '1');
            $mform->addHelpButton('showothermanagers', 'showothermanagers', 'block_iomad_company_admin');
        } else {
            $mform->addElement('hidden', 'showothermanagers', 0);
        }
        $mform->addElement('submit', 'updateselection', get_string('updatedepartmentusersselection', 'block_iomad_company_admin'));
        if (count($this->potentialusers->find_users('')) || count($this->currentusers->find_users(''))) {
            $mform->addElement('html', '<table summary=""
                                        class="companymanagertable addremovetable generaltable generalbox boxaligncenter"
                                        cellspacing="0">
                <tr>
                  <td id="existingcell">');
            $mform->addElement('html', $this->currentusers->display(true));
            $mform->addElement('html', '
                  </td>
                  <td id="buttonscell">
                      <div id="addcontrols">
                          <input name="add" id="add" type="submit" value="&#x25C4;&nbsp;' . get_string('add') . '" title="Add" /><br />

                      </div>

                      <div id="removecontrols">
                          <input name="remove" id="remove" type="submit" value="' . get_string('remove') . '&nbsp;&#x25BA;" title="Remove" />
                      </div>
                  </td>
                  <td id="potentialcell">');
            $mform->addElement('html', $this->potentialusers->display(true));
            $mform->addElement('html', '
                  </td>
                </tr>
              </table>');
        } else {
            $mform->addElement('html', get_string('nousers', 'block_iomad_company_admin') . ' <a href="' . new moodle_url('/blocks/iomad_company_admin/company_user_create_form.php?companyid=' . $this->selectedcompany) . '">Create one now</a>');
        }
    }
 public function definition()
 {
     global $CFG, $PAGE, $DB;
     $context = context_system::instance();
     $mform =& $this->_form;
     $strrequired = get_string('required');
     $mform->addElement('hidden', 'templateid', $this->templateid);
     $mform->addElement('hidden', 'templatename', $this->templaterecord->name);
     $mform->addElement('hidden', 'companyid', $this->companyid);
     $mform->setType('templateid', PARAM_INT);
     $mform->setType('companyid', PARAM_INT);
     $mform->setType('templatename', PARAM_CLEAN);
     $company = new company($this->companyid);
     // Then show the fields about where this block appears.
     $mform->addElement('header', 'header', get_string('email_template', 'local_email', array('name' => $this->templaterecord->name, 'companyname' => $company->get_name())));
     $mform->addElement('text', 'subject', get_string('subject', 'local_email'), array('size' => 100));
     $mform->setType('subject', PARAM_NOTAGS);
     $mform->addRule('subject', $strrequired, 'required');
     /* GWL : To replace text area with Rich text editor make textarea code commented 
     		$mform->addElement('textarea', 'body_editor', get_string('body', 'local_email'), 'wrap="virtual" rows="50" cols="100"');
     		 $mform->addHelpButton('body_editor', 'coursesummary');
     		 $mform->setType('body_editor', PARAM_NOTAGS);
     		 $mform->addRule('body_editor', $strrequired, 'required');
              */
     $mform->addElement('editor', 'emailbody_editor', get_string('body', 'local_email'), null, $this->editoroptions);
     $mform->setType('emailbody', PARAM_RAW);
     //end
     $vars = EmailVars::vars();
     $options = "<option value=''>" . get_string('select_email_var', 'local_email') . "</option>";
     foreach ($vars as $i) {
         $options .= "<option value='{{$i}}'>{$i}</option>";
     }
     /*GWL : Code Add for Placeholders $select = "<select class='emailvars' onchange='window.Perficio.onSelectEmailVar(this)'>
       $options</select>";*/
     $select = "<select class='emailvars'>{$options}</select>";
     // End Code
     $html = "<div class='fitem'><div class='fitemtitle'></div><div class='felement'>\n                 {$select}</div></div>";
     $mform->addElement('html', $html);
     global $PAGE;
     //GWL : Add JS
     $PAGE->requires->jquery();
     $PAGE->requires->js('/local/email/module.js');
     $submitlabel = null;
     // Default.
     if ($this->isadding) {
         $submitlabel = get_string('save_to_override_default_template', 'local_email');
         $mform->addElement('hidden', 'createnew', 1);
         $mform->setType('createnew', PARAM_INT);
     }
     $this->add_action_buttons(true, $submitlabel);
 }
 public function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $company = new company($this->selectedcompany);
     if (!($parentnode = company::get_company_parentnode($company->id))) {
         // Company has not been set up, possibly from before an upgrade.
         company::initialise_departments($company->id);
     }
     if (!empty($this->departmentid)) {
         $departmentslist = company::get_all_subdepartments($this->departmentid);
     } else {
         $departmentslist = company::get_all_departments($company->id);
     }
     if (!empty($this->departmentid)) {
         $department = company::get_departmentbyid($this->departmentid);
     } else {
         $department = company::get_company_parentnode($this->selectedcompany);
     }
     $subdepartmentslist = company::get_subdepartments_list($department);
     $subdepartments = company::get_subdepartments($department);
     // Create the sub department checkboxes html.
     $subdepartmenthtml = "";
     if (!empty($subdepartmentslist)) {
         $subdepartmenthtml = "<div class='locationlist_container checkboxcontainer'>";
         $subdepartmenthtml .= "<p>" . get_string('subdepartments', 'block_iomad_company_admin') . "</p>";
         foreach ($subdepartmentslist as $key => $value) {
             $subdepartmenthtml .= '<input type = "checkbox" name = "departmentids[]" value="' . $key . '" /> ' . $value . '</br>';
         }
         $subdepartmenthtml .= '</div>';
         $subdepartmenthtml .= '<p><br/><input type="checkbox" id="selectallcheckbox" />Select all / Deselect All</p>';
     }
     // Then show the fields about where this block appears.
     $mform->addElement('header', 'header', get_string('companydepartment', 'block_iomad_company_admin') . $company->get_name());
     $mform->addElement('select', 'deptid', get_string('department', 'block_iomad_company_admin'), $departmentslist);
     $mform->addElement('html', $subdepartmenthtml);
     $buttonarray = array();
     $buttonarray[] = $mform->createElement('submit', 'create', get_string('createdepartment', 'block_iomad_company_admin'));
     if (!empty($subdepartmentslist)) {
         $buttonarray[] = $mform->createElement('submit', 'edit', get_string('editdepartments', 'block_iomad_company_admin'), array('class' => 'editdepart'));
         $buttonarray[] = $mform->createElement('submit', 'delete', get_string('deletedepartment', 'block_iomad_company_admin'));
     }
     $mform->addGroup($buttonarray, '', array(' '), ' ', false);
 }
 public function definition_after_data()
 {
     $mform =& $this->_form;
     // Adding the elements in the definition_after_data function rather than in the definition
     // function so that when the currentcourses or potentialcourses get changed in the process
     // function, the changes get displayed, rather than the lists as they are before processing.
     $company = new company($this->selectedcompany);
     $mform->addElement('header', 'header', get_string('company_courses_for', 'block_iomad_company_admin', $company->get_name()));
     $mform->addElement('select', 'departmentid', get_string('department', 'block_iomad_company_admin'), $this->subhierarchieslist);
     $mform->addElement('submit', 'updateselection', get_string('updatedepartmentusersselection', 'block_iomad_company_admin'));
     $mform->addElement('html', "<div class='fitem'><div class='fitemtitle'>" . get_string('selectenrolmentcourse', 'block_iomad_company_admin') . "</div><div class='felement'>");
     $mform->addElement('html', $this->currentcourses->display(true));
     $mform->addElement('html', "</div></div>");
     if ($this->currentcourses) {
         $this->add_action_buttons(true, get_string('enrolunenrollusers', 'block_iomad_company_admin'));
     } else {
         $mform->addElement('html', get_string('nocourses', 'block_iomad_company_admin'));
     }
 }
    public function definition_after_data()
    {
        global $USER;
        $mform =& $this->_form;
        // Adding the elements in the definition_after_data function rather than in the definition function
        // so that when the currentusers or potentialusers get changed in the process function, the
        // changes get displayed, rather than the lists as they are before processing.
        $company = new company($this->selectedcompany);
        $mform->addElement('header', 'header', get_string('company_users_for', 'block_iomad_company_admin', $company->get_name()));
        if (count($this->potentialusers->find_users('')) || count($this->currentusers->find_users(''))) {
            $mform->addElement('html', '<table summary=""
                                        class="companyusertable addremovetable generaltable generalbox boxaligncenter"
                                        cellspacing="0">
                <tr>
                  <td id="existingcell">');
            $mform->addElement('html', $this->currentusers->display(true));
            $mform->addElement('html', '
                  </td>
                  <td id="buttonscell">
                      <div id="addcontrols">
                          <input name="add" id="add" type="submit" value="&nbsp;' . get_string('add') . '" title="Add" /><br />

                      </div>

                      <div id="removecontrols">
                          <input name="remove" id="remove" type="submit" value="' . get_string('remove') . '&nbsp;" title="Remove" />
                      </div>
                  </td>
                  <td id="potentialcell">');
            $mform->addElement('html', $this->potentialusers->display(true));
            $mform->addElement('html', '
                  </td>
                </tr>
              </table>');
        } else {
            $mform->addElement('html', get_string('nousers', 'block_iomad_company_admin') . ' <a href="' . new moodle_url('/blocks/iomad_company_admin/company_user_create_form.php?companyid=' . $this->selectedcompany) . '">Create one now</a>');
        }
    }
$linkurl = new moodle_url('/blocks/iomad_company_admin/editcompanies.php');
company_admin_fix_breadcrumb($PAGE, $linktext, $linkurl);
echo $OUTPUT->header();
$companyids = $DB->get_records_menu('company', array(), 'id, name');
//$companyids['none'] = get_string('nocompany', 'block_iomad_company_admin');
$companyids[''] = get_string('selectacompany', 'block_iomad_company_admin');
ksort($companyids);
$companyselect = new single_select(new moodle_url('/local/company_navigation/manage_company.php'), 'companyid', $companyids, $companyid);
$companyselect->label = get_string('company', 'block_iomad_company_admin');
$companyselect->formid = 'choosecompany';
echo html_writer::tag('div', $OUTPUT->render($companyselect), array('id' => 'iomad_company_selector')) . '</br>';
// get company detail
if ($companyid) {
    $company = new company($companyid);
    $table = new html_table();
    $table->head = array(get_string('companyadminstration', 'local_company_navigation', $company->get_name()));
    if ($company->get()) {
        // check company record exist and set it to session variable as current company
        $SESSION->currenteditingcompany = $company->id;
    }
    if (isset($SESSION->currenteditingcompany)) {
        $companymanagelinks = get_company_manage_links($SESSION->currenteditingcompany);
        foreach ($companymanagelinks as $linktext => $linkurl) {
            $link = $linktext;
            if ($linkurl) {
                $link = '<a href=' . $linkurl . '>' . $linktext . '</a>';
            }
            $table->data[] = array($link);
        }
        if ($companymanagelinks) {
            echo html_writer::table($table);
        echo $OUTPUT->footer();
        die;
    } else {
        if (data_submitted()) {
            // Actually delete license.
            if (!$DB->delete_records('companylicense', array('id' => $delete))) {
                print_error('error while deleting license');
            }
        }
    }
}
$blockpage->display_header();
// Check we can actually do anything on this page.
iomad::require_capability('block/iomad_company_admin:view_licenses', $context);
$company = new company($companyid);
echo "<h3>" . $company->get_name() . "</h3>";
// Get the number of companies.
$objectcount = $DB->count_records('companylicense', array('companyid' => $companyid));
echo $OUTPUT->paging_bar($objectcount, $page, $perpage, $baseurl);
flush();
$stredit = get_string('edit');
$strdelete = get_string('delete');
$straddlicense = get_string('licenseaddnew', 'block_iomad_company_admin');
$strlicensename = get_string('licensename', 'block_iomad_company_admin');
$strcoursesname = get_string('allocatedcourses', 'block_iomad_company_admin');
$strlicenseshelflife = get_string('licenseexpires', 'block_iomad_company_admin');
$strlicenseduration = get_string('licenseduration', 'block_iomad_company_admin');
$strlicenseallocated = get_string('licenseallocated', 'block_iomad_company_admin');
$strlicenseremaining = get_string('licenseremaining', 'block_iomad_company_admin');
$table = new html_table();
$table->head = array($strlicensename, $strcoursesname, $strlicenseshelflife, $strlicenseduration, $strlicenseallocated, $strlicenseremaining, "", "");
 public function definition()
 {
     global $CFG, $USER;
     $mform =& $this->_form;
     $company = new company($this->selectedcompany);
     if (!($parentnode = company::get_company_parentnode($company->id))) {
         // Company has not been set up, possibly from before an upgrade.
         company::initialise_departments($company->id);
     }
     if (!empty($this->departmentid)) {
         $departmentslist = company::get_all_subdepartments($this->departmentid);
     } else {
         $departmentslist = company::get_all_departments($company->id);
     }
     if (!empty($this->departmentid)) {
         $department = company::get_departmentbyid($this->departmentid);
     } else {
         $department = company::get_company_parentnode($this->selectedcompany);
     }
     /* GWL : Get Company Parent Node */
     $parentnode = company::get_company_parentnode($this->selectedcompany);
     $context = context_system::instance();
     if (iomad::has_capability('block/iomad_company_admin:edit_all_departments', $context)) {
         $userhierarchylevel = $parentnode->id;
     } else {
         $userlevel = company::get_userlevel($USER);
         $userhierarchylevel = $userlevel->id;
     }
     $subdepartmentslist = company::get_subdepartments_list($department);
     $subdepartments = company::get_subdepartments($department);
     $regionlistarr = array('' => get_string('choose'));
     $showregiondropdown = 1;
     $showlocationdropdown = 1;
     if ($parentnode->id == $userhierarchylevel) {
         $regionlist = company::get_all_regions($company->id);
         foreach ($regionlist as $region) {
             $regionlistarr[$region->id] = $region->name;
         }
     } else {
         $regionlist = company::get_my_region($userhierarchylevel);
         if (!$regionlist) {
             $showregiondropdown = 0;
         } else {
             $regionlistarr[$regionlist->id] = $regionlist->name;
         }
     }
     // Create the sub department checkboxes html.
     $subdepartmenthtml = "<div class='departments_container'></div>";
     $locationlist = array('' => get_string('choose'));
     if ($parentnode->id != $userhierarchylevel && empty($regionlist)) {
         $mylocationlist = company::get_my_location($userhierarchylevel);
         if ($mylocationlist) {
             $locationlist[$mylocationlist->id] = $mylocationlist->name;
         } else {
             $showlocationdropdown = 0;
         }
     }
     /* if (!empty($subdepartmentslist)) {
               $subdepartmenthtml = "<p>" . get_string('subdepartments', 'block_iomad_company_admin') .
               "</p>";
               foreach ($subdepartmentslist as $key => $value) {
     
               $subdepartmenthtml .= '<input type = "checkbox" name = "departmentids[]" value="' .
               $key . '" /> ' . $value . '</br>';
               }
               } */
     // Then show the fields about where this block appears.
     $mform->addElement('header', 'header', get_string('companydepartment', 'block_iomad_company_admin') . $company->get_name());
     if ($showregiondropdown) {
         $mform->addElement('select', 'regionid', get_string('region', 'block_iomad_company_admin'), $regionlistarr, array('class' => 'companyregion'));
         $mform->addRule('regionid', get_string('regionnotselect', 'block_iomad_company_admin'), 'required', null, 'client');
     }
     if ($showlocationdropdown) {
         $mform->addElement('select', 'locationid', get_string('location', 'block_iomad_company_admin'), $locationlist, array('class' => 'companylocation'));
         $mform->addRule('locationid', get_string('locationnotselect', 'block_iomad_company_admin'), 'required', null, 'client');
     }
     //$mform->addElement('html', $subdepartmenthtml);
     $mform->addElement('select', 'deptid', get_string('department', 'block_iomad_company_admin'), $locationlist, array('class' => 'dept_container'));
     $mform->addElement('html', $subdepartmenthtml);
     $buttonarray = array();
     $attr = array();
     if (!$showlocationdropdown) {
         $attr = array('disabled' => 'disabled');
     }
     $buttonarray[] = $mform->createElement('submit', 'create', get_string('createdepartment', 'block_iomad_company_admin'), $attr);
     // if (!empty($subdepartmentslist)) {
     $buttonarray[] = $mform->createElement('submit', 'edit', get_string('editdepartments', 'block_iomad_company_admin'), array('disabled' => 'disabled', 'class' => 'editdepart'));
     $buttonarray[] = $mform->createElement('submit', 'delete', get_string('deletedepartment', 'block_iomad_company_admin'), array('disabled' => 'disabled'));
     //}
     $mform->addGroup($buttonarray, '', array(' '), ' ', false);
 }
            if ($DB->delete_records('email_template', array('id' => $delete))) {
                $transaction->allow_commit();
                redirect($returnurl);
            } else {
                $transaction->rollback();
                echo $OUTPUT->header();
                echo $OUTPUT->notification($returnurl, get_string('deletednot', '', $template->name));
                die;
            }
            $transaction->rollback();
        }
    }
}
$blockpage->display_header();
$company = new company($companyid);
echo get_string('email_templates_for', $block, $company->get_name());
// Check we can actually do anything on this page.
iomad::require_capability('local/email:list', $context);
// Get the number of templates.
$objectcount = $DB->count_records('email_template');
echo $OUTPUT->paging_bar($objectcount, $page, $perpage, $baseurl);
flush();
// Sort the keys of the global $email object, the make sure we have that and the
// recordset we'll get next in the same order.
$configtemplates = array_keys($email);
sort($configtemplates);
$ntemplates = count($configtemplates);
// Returns true if user is allowed to send emails using a particular template.
function allow_sending_to_template($templatename)
{
    return in_array($templatename, array('advertise_classroom_based_course', ''));
            if ($DB->delete_records('classroom', array('id' => $delete))) {
                $transaction->allow_commit();
                redirect($returnurl);
            } else {
                $transaction->rollback();
                echo $OUTPUT->header();
                echo $OUTPUT->notification($returnurl, get_string('deletednot', '', $classroom->name));
                die;
            }
            $transaction->rollback();
        }
    }
}
$blockpage->display_header();
$company = new company($companyid);
echo get_string('classrooms_for', $block, $company->get_name());
// Check we can actually do anything on this page.
iomad::require_capability('block/iomad_company_admin:classrooms', $context);
// Get the number of templates.
$objectcount = $DB->count_records('classroom', array('companyid' => $companyid));
echo $OUTPUT->paging_bar($objectcount, $page, $perpage, $baseurl);
flush();
if ($classrooms = $DB->get_recordset('classroom', array('companyid' => $companyid), 'name', '*', $page, $perpage)) {
    $stredit = get_string('edit');
    $strdelete = get_string('delete');
    $table = new html_table();
    $table->head = array("Name", "Capacity", "", "");
    $table->align = array("left", "left", "center", "center");
    $table->width = "95%";
    foreach ($classrooms as $classroom) {
        if (iomad::has_capability('block/iomad_company_admin:classrooms_delete', $context)) {