Ejemplo n.º 1
0
 $user_name = $argv[$last_arg];
 //Get user_id from user_name
 $ulf = new UserListFactory();
 $ulf->getByUserName($user_name);
 if ($ulf->getRecordCount() == 1) {
     echo "Found user, apply administrator permissions...\n";
     ob_flush();
     $u_obj = $ulf->getCurrent();
     //Create new Permission Group just for this purpose.
     $pf = new PermissionFactory();
     $pf->StartTransaction();
     //Apply all preset flags, including 0 => "system"
     $preset_flags = array_merge(array(0), array_keys($pf->getOptions('preset_flags')));
     $pcf = new PermissionControlFactory();
     $pcf->setCompany($u_obj->getCompany());
     $pcf->setLevel(25);
     $pcf->setName('Administrator Fix (' . rand(1, 1000) . ')');
     $pcf->setDescription('Created By set_admin_permissions.php');
     if ($pcf->isValid()) {
         $pcf_id = $pcf->Save(FALSE);
         $pcf->setUser(array($u_obj->getId()));
         $pcf->Save();
         if ($pf->applyPreset($pcf_id, 40, $preset_flags) == TRUE) {
             echo "Success!\n";
         }
     }
     //$pf->FailTransaction();
     $pf->CommitTransaction();
 } elseif ($ulf->getRecordCount() > 2) {
     echo "Found more then one user with the same user name, not updating permissions!\n";
 } else {