Dokeos PHP Cross Reference Learning Management Systems

Source: /main/admin/group_add.php - 149 lines - 6154 bytes - Summary - Text - Print

   1  <?php
   2  /* For licensing terms, see /dokeos_license.txt */
   3  
   4  /**
   5  * @package dokeos.admin
   6  */
   7  
   8  // Language files that should be included
   9  $language_file = array('admin', 'registration','userInfo');
  10  
  11  $cidReset = true;
  12  
  13  // Including necessary libraries.
  14  require  '../inc/global.inc.php';
  15  $libpath = api_get_path(LIBRARY_PATH);
  16  require_once $libpath.'fileManage.lib.php';
  17  require_once $libpath.'fileUpload.lib.php';
  18  require_once $libpath.'group_portal_manager.lib.php';
  19  require_once $libpath.'formvalidator/FormValidator.class.php';
  20  require_once $libpath.'image.lib.php';
  21  
  22  // Section for the tabs
  23  $this_section = SECTION_PLATFORM_ADMIN;
  24  
  25  // User permissions
  26  api_protect_admin_script();
  27  
  28  // Database table definitions
  29  $table_admin     = Database :: get_main_table(TABLE_MAIN_ADMIN);
  30  $table_user     = Database :: get_main_table(TABLE_MAIN_USER);
  31  $database         = Database::get_main_database();
  32  
  33  if (!empty($_GET['message'])) {
  34      $message = urldecode($_GET['message']);
  35  }
  36  
  37  $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  38  $tool_name = get_lang('AddGroups');
  39  
  40  // Create the form
  41  $form = new FormValidator('group_add');
  42  $form->addElement('header', '', $tool_name);
  43  
  44  // name
  45  $form->addElement('text', 'name', get_lang('Name'));
  46  $form->applyFilter('name', 'html_filter');
  47  $form->applyFilter('name', 'trim');
  48  $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  49  
  50  // Description
  51  $form->addElement('text', 'description', get_lang('Description'));
  52  $form->applyFilter('description', 'html_filter');
  53  $form->applyFilter('description', 'trim');
  54  
  55  
  56  // url
  57  $form->addElement('text', 'url', get_lang('URL'));
  58  $form->applyFilter('url', 'html_filter');
  59  $form->applyFilter('url', 'trim');
  60  
  61  // Picture
  62  $form->addElement('file', 'picture', get_lang('AddPicture'));
  63  $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  64  $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  65  
  66  // Status
  67  $status = array();
  68  $status[GROUP_PERMISSION_OPEN]         = get_lang('Open');
  69  $status[GROUP_PERMISSION_CLOSED]    = get_lang('Closed');
  70  
  71  $form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status);
  72  
  73  // Set default values
  74  $defaults['status'] = GROUP_PERMISSION_OPEN;
  75  
  76  $form->setDefaults($defaults);
  77  
  78  // Submit button
  79  $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
  80  
  81  // Validate form
  82  if( $form->validate()) {
  83      $check = Security::check_token('post');
  84      if ($check) {
  85          $values = $form->exportValues();
  86  
  87          $picture_element = & $form->getElement('picture');
  88          $picture         = $picture_element->getValue();
  89          $picture_uri     = '';
  90          $name             = $values['name'];
  91          $description    = $values['description'];
  92          $url             = $values['url'];    
  93          $status         = intval($values['visibility']);
  94          $picture         = $_FILES['picture'];
  95  
  96          $group_id = GroupPortalManager::add($name, $description, $url, $status);
  97          
  98          if (!empty($picture['name'])) {
  99              $picture_uri = GroupPortalManager::update_group_picture($group_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']);
 100              GroupPortalManager::update($group_id, $name, $description, $url,$status, $picture_uri);
 101          }
 102  
 103          //@todo send emails
 104          
 105  /*        if (!empty($email) && $send_mail) {
 106              $recipient_name = api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS);
 107              $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
 108  
 109              $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
 110              $email_admin = api_get_setting('emailAdministrator');
 111  
 112              if ($_configuration['multiple_access_urls'] == true) {
 113                  $access_url_id = api_get_current_access_url_id();
 114                  if ($access_url_id != -1) { 
 115                      $url = api_get_access_url($access_url_id);
 116                      $emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
 117                  }
 118              }
 119              else {
 120                  $emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $_configuration['root_web'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
 121              }
 122              @api_mail($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
 123          }*/
 124          
 125          Security::clear_token();
 126          $tok = Security::get_token();
 127          header('Location: group_list.php?action=show_message&message='.urlencode(get_lang('GroupAdded')).'&sec_token='.$tok);
 128              exit ();
 129      }
 130  } else {
 131      if (isset($_POST['submit'])) {
 132          Security::clear_token();
 133      }
 134      $token = Security::get_token();
 135      $form->addElement('hidden', 'sec_token');
 136      $form->setConstants(array('sec_token' => $token));
 137  }
 138  
 139  // Display form
 140  Display::display_header($tool_name);
 141  echo '<div id="content">';
 142  //api_display_tool_title($tool_name);
 143  if(!empty($message)){
 144      Display::display_normal_message(stripslashes($message));
 145  }
 146  $form->display();
 147  echo '</div>';
 148  // Footer
 149  Display::display_footer();

title

Description

title

Description

title

Description

title

title

Body