setTPL("user_form.tpl"); $form = new HTML_QuickForm("NewForm"); if(isset($_POST['user_add'])&&('Add a new user'==$_POST['user_add'])) { //we have just come through here from the admin page, so unset Post vars unset ($_POST); } //}}} function process_data($args) { /** * Process Data * * This is the callback function to handle the processing of the QF * @author Tristan Coetzee * @param $args Contains the form variables supplied by HTML_QF * @version 0.1.0 */ global $LUA; global $ini; //{{{ define and set liveuser default user type // $user_type = LIVEUSER_ANONYMOUS_TYPE_ID; // lowest user level: anonymous $user_type = LIVEUSER_USER_TYPE_ID; // highest user level // $user_type = LIVEUSER_ADMIN_TYPE_ID; // lowest admin level // $user_type = LIVEUSER_AREAADMIN_TYPE_ID; // area admin level (lookup area admin) // $user_type = LIVEUSER_SUPERADMIN_TYPE_ID; // all rights granted // $user_type = LIVEUSER_MASTERADMIN_TYPE_ID; // highest admin level //}}} if('Add User!'==$args['btnAddEdit']) { //submit button was pressed $user_data = array( 'auth_user_id'=>$args['lu_auth_user_id'], 'handle'=>$args['lu_handle'], 'passwd'=>$args['lu_passwd'], 'is_active'=>'1', 'user_alias'=>$args['txtUserAlias'], 'user_email'=>$args['txtUserEmail'], 'user_phone'=>$args['txtUserPhone'], 'user_cost_multiplier'=>$args['txtUserCostMult'], 'perm_type'=>$user_type ); $perm_user_id = $LUA->addUser($user_data); if ($perm_user_id===false) { print_r($LUA->getErrors()); die("Error adding user"); } else { if(isset($args['sel_priv_id'])&&!empty($args['sel_priv_id'])) { $group_id = $args['sel_priv_id']; } else { $group_id = 0; } //create permissions in usergroups table using new perm_user_id $user_perm = array( 'perm_user_id'=>$perm_user_id, 'group_id'=>$group_id ); if(!$LUA->perm->addUserToGroup($user_perm)) { print_r($LUA->getErrors()); die("Error adding user to group"); } else { //add user to sip.conf if needed... if(isset($args['sipconf'])&&!empty($args['sipconf'])) { $fp = fopen($ini['Asterisk']['conf_path'] . $ini['Asterisk']['conf_filename'], "ab"); if($fp) { $contentStr = "\n[{$args['txtUserPhone']}]\n".$args['sipconf']."\n\n"; fwrite($fp,$contentStr); fclose($fp); } } return "User Added Successfully!"; } } } } //end of process_data callback function if(isset($ini['Asterisk']['synch_users'])&&$ini['Asterisk']['synch_users']==true) { $SIPconf = getSIPConfig($ini); if($SIPconf) { $chkSIP = true; $conf_area = $form->addElement('textarea','sipconf','Asterisk Configuration',array('rows'=>20,'cols'=>50)); $form->setDefaults(array('sipconf'=>"disallow=all\nallow=g729\nallowguest=yes\ntype=friend\ncallerid=\nmailbox= @post-office\n;restrictcid=no\nusername=\nhost=dynamic\n;nat=yes\ncanreinvite=no\nqualify=5000\ndtmfmode=rfc2833\n;callgroup=3\n;pickupgroup=3,31\n;outgoinglimit=1\n\n")); $tpl->assign('sip_conf_found',true); } else { $chkSIP = false; } //var_dump($SIPconf); } else { $chkSIP = false; } //{{{ add basic form elements $form->addElement('header',"hdrTop","Add User"); //$form->addElement('text','lu_auth_user_id',"User ID: ",array('maxlength'=>'100')); $form->addElement('text','lu_handle',"Handle: ",array('maxlength'=>'100')); $form->addElement('text','txtUserAlias',"User Name: ",array('maxlength'=>'100')); $form->addElement('text','txtUserEmail',"Email: ",array('maxlength'=>'100')); $form->addElement('text','txtUserPhone',"Phone: ",array('maxlength'=>'100')); $form->addElement('text','txtUserCostMult',"Cost Multiplier: ",array('maxlength'=>'20')); $form->addElement('password','lu_passwd',"Password: ",array('maxlength'=>'100')); $form->addElement('password','lu_confirm_pwd',"Confirm Password: ",array('maxlength'=>'20')); $form->addElement('submit','btnAddEdit','Add User!'); //}}} //{{{ add select elements $yesno = array("Y","N"); $active =& $form->addElement('select','sel_isActive','Active: ',$yesno); //{{{ create select privilege element $pr_query = "SELECT `group_id`,`group_define_name` FROM `liveuser_groups`"; $pr_res = $db->query($pr_query); if(handleError($pr_res)) { $privileges = array(); while($pr_res->fetchInto($pr_rec)) { $privileges[$pr_rec['group_id']] = $pr_rec['group_define_name']; } $form->addElement('select','sel_priv_id','Select System Privileges: ',$privileges); } //}}} //}}} //{{{ create filters $form->applyFilter('all','trim'); //}}} //{{{ create rules //$form->addRule('lu_auth_user_id',"This is a required value",'required'); $form->addRule('lu_handle',"This is a required value",'required'); $form->addRule('lu_passwd',"This is a required value",'required'); $form->addRule('lu_confirm_pwd',"This is a required value",'required'); $form->addRule('sel_group_id',"This is a required value",'required'); $form->addRule(array('lu_passwd','lu_confirm_pwd'),"The passwords must match",'compare'); $form->addRule('txtUserCostMult',"This is a numeric value",'numeric'); //}}} //{{{ validate form if($form->validate()) { $result = $form->process('process_data','false'); $form->addElement('text','txtResult',$result); } else { } //}}} //{{{ assign form to tpl and display form $tpl->display(&$form); //}}} ?>