Exemplo n.º 1
0
 public function add()
 {
     # code...
     if (isset($_POST['addUserBtn']) || isset($_POST['editUserBtn'])) {
         $user = new Profile();
         $user->setUsername(Utils::sanitize($_POST['username']));
         $user->setPassword(Utils::sanitize($_POST['password']));
         $user->setShortcode(Utils::sanitize($_POST['shortcode']));
         $user->setSMSC(Utils::sanitize($_POST['smsc']));
         $user->setType('send_profile');
         // $user->save();
         isset($_POST['editUserBtn']) ? $user->update() : $user->save();
         $msg = isset($_POST['editUserBtn']) ? 'Profile Successfully Updated' : 'New Profile Added';
         $this->notifyBar('success', $msg);
         $u = Profile::getAll();
         $this->setVariable('users', $u);
         $this->setView('', 'list-user');
     } else {
         $this->setView('', 'add-new-user');
     }
 }
 /**
  * Init profiles during installation :
  * - add rights in profile table for the current user's profile
  * - current profile has all rights on the plugin
  */
 static function initProfile()
 {
     $pfProfile = new self();
     $profile = new Profile();
     $a_rights = $pfProfile->getAllRights();
     foreach ($a_rights as $data) {
         if (countElementsInTable("glpi_profilerights", "`name` = '" . $data['field'] . "'") == 0) {
             ProfileRight::addProfileRights(array($data['field']));
             $_SESSION['glpiactiveprofile'][$data['field']] = 0;
         }
     }
     // Add all rights to current profile of the user
     if (isset($_SESSION['glpiactiveprofile'])) {
         $dataprofile = array();
         $dataprofile['id'] = $_SESSION['glpiactiveprofile']['id'];
         $profile->getFromDB($_SESSION['glpiactiveprofile']['id']);
         foreach ($a_rights as $info) {
             if (is_array($info) && (!empty($info['itemtype']) || !empty($info['rights'])) && !empty($info['label']) && !empty($info['field'])) {
                 if (isset($info['rights'])) {
                     $rights = $info['rights'];
                 } else {
                     $rights = $profile->getRightsFor($info['itemtype']);
                 }
                 foreach ($rights as $right => $label) {
                     $dataprofile['_' . $info['field']][$right] = 1;
                     $_SESSION['glpiactiveprofile'][$data['field']] = $right;
                 }
             }
         }
         $profile->update($dataprofile);
     }
 }
Exemplo n.º 3
0
 /**
  * test deleting a Profile that does not exist
  *
  * @expectedException PDOException
  **/
 public function testDeleteInvalidProfile()
 {
     // create a Profile and try to delete it without actually inserting it
     $profile = new Profile(null, $this->VALID_ATHANDLE, $this->VALID_EMAIL, $this->VALID_PHONE);
     $profile->update($this->getPDO());
 }
Exemplo n.º 4
0
<?php

require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
require_once "profile.php";
$pdo = connectToEncryptedMySQL("/etc/apache2/data-design/vhooker.ini");
$profile = new Profile(null, 1, "this is from PHP");
$profile->insert($pdo);
$profile->setProfile("now I changed the message");
$profile->update($pdo);
$profile->delete($pdo);
Exemplo n.º 5
0
 static function createAnonProfile()
 {
     // Get the anon user's IP, and turn it into a nickname
     list($proxy, $ip) = common_client_ip();
     // IP + time + random number should help to avoid collisions
     $baseNickname = $ip . '-' . time() . '-' . common_good_rand(5);
     $profile = new Profile();
     $profile->nickname = $baseNickname;
     $id = $profile->insert();
     if (!$id) {
         // TRANS: Server exception.
         throw new ServerException(_m("Could not create anonymous user session."));
     }
     // Stick the Profile ID into the nickname
     $orig = clone $profile;
     $profile->nickname = 'anon-' . $id . '-' . $baseNickname;
     $result = $profile->update($orig);
     if (!$result) {
         // TRANS: Server exception.
         throw new ServerException(_m("Could not create anonymous user session."));
     }
     common_log(LOG_INFO, "AnonymousFavePlugin - created profile for anonymous user from IP: " . $ip . ', nickname = ' . $profile->nickname);
     return $profile;
 }
Exemplo n.º 6
0
 function pre_deleteItem()
 {
     if ($this->getFromDB($this->fields["id"])) {
         $name = $this->fields['name'];
         $itemtype = $this->fields['itemtype'];
         //Delete all network ports
         self::deleteNetworking($itemtype);
         //Drop all dropdowns associated with itemtype
         self::deleteDropdownsForItemtype($itemtype);
         //Delete loans associated with this type
         self::deleteLoans($itemtype);
         //Delete loans associated with this type
         self::deleteUnicity($itemtype);
         //Delete reservations with this tyoe
         self::deleteReservations($itemtype);
         self::deleteReservationItems($itemtype);
         //Remove datainjection specific file
         self::deleteInjectionFile($name);
         //Delete profile informations associated with this type
         PluginGenericobjectProfile::deleteTypeFromProfile($itemtype);
         self::deleteTicketAssignation($itemtype);
         //Remove associations to simcards with this type
         self::deleteSimcardAssignation($itemtype);
         //Remove existing datainjection models
         self::removeDataInjectionModels($itemtype);
         //Delete specific locale directory
         self::deleteLocales($name, $itemtype);
         self::deleteItemtypeReferencesInGLPI($itemtype);
         self::deleteItemTypeFilesAndClasses($name, $this->getTable(), $itemtype);
         //self::deleteNotepad($itemtype);
         if (preg_match("/PluginGenericobject(.*)/", $itemtype, $results)) {
             $newrightname = 'plugin_genericobject_' . strtolower($results[1]) . 's';
             ProfileRight::deleteProfileRights(array($newrightname));
         }
         $prof = new Profile();
         $profiles = getAllDatasFromTable('glpi_profiles');
         foreach ($profiles as $profile) {
             $helpdesk_item_types = json_decode($profile['helpdesk_item_type'], true);
             if ($helpdesk_item_types !== null) {
                 $index = array_search($itemtype, $helpdesk_item_types);
                 if ($index) {
                     unset($helpdesk_item_types[$index]);
                     $tmp['id'] = $profile['id'];
                     $tmp['helpdesk_item_type'] = json_encode($helpdesk_item_types);
                     $prof->update($tmp);
                 }
             }
         }
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 7
0
 You should have received a copy of the GNU General Public License
 along with Genericobject. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
 @package   genericobject
 @author    the genericobject plugin team
 @copyright Copyright (c) 2010-2011 Order plugin team
 @license   GPLv2+
            http://www.gnu.org/licenses/gpl.txt
 @link      https://forge.indepnet.net/projects/genericobject
 @link      http://www.glpi-project.org/
 @since     2009
 ---------------------------------------------------------------------- */
include "../../../inc/includes.php";
Session::checkRight("profile", UPDATE);
_log($_POST);
$prof = new Profile();
/* save profile */
if (isset($_POST['update_all_rights']) && isset($_POST['itemtype'])) {
    $profiles = array();
    foreach ($_POST as $key => $val) {
        if (preg_match("/^profile_/", $key)) {
            $id = preg_replace("/^profile_/", "", $key);
            $profiles[$id] = array("id" => $id, "_" . PluginGenericobjectProfile::getProfileNameForItemtype($_POST['itemtype']) => $val);
        }
    }
    _log($profiles);
    foreach ($profiles as $profile_id => $input) {
        $prof->update($input);
    }
}
Html::redirect($_SERVER['HTTP_REFERER']);
Exemplo n.º 8
0
 public static function updateProfile(Profile $profile, ActivityObject $object, array $hints = array())
 {
     $orig = clone $profile;
     // Existing nickname is better than nothing.
     if (!array_key_exists('nickname', $hints)) {
         $hints['nickname'] = $profile->nickname;
     }
     $nickname = self::getActivityObjectNickname($object, $hints);
     if (!empty($nickname)) {
         $profile->nickname = $nickname;
     }
     if (!empty($object->title)) {
         $profile->fullname = $object->title;
     } else {
         if (array_key_exists('fullname', $hints)) {
             $profile->fullname = $hints['fullname'];
         }
     }
     if (!empty($object->link)) {
         $profile->profileurl = $object->link;
     } else {
         if (array_key_exists('profileurl', $hints)) {
             $profile->profileurl = $hints['profileurl'];
         } else {
             if (common_valid_http_url($object->id)) {
                 $profile->profileurl = $object->id;
             }
         }
     }
     $bio = self::getActivityObjectBio($object, $hints);
     if (!empty($bio)) {
         $profile->bio = $bio;
     }
     $location = self::getActivityObjectLocation($object, $hints);
     if (!empty($location)) {
         $profile->location = $location;
     }
     $homepage = self::getActivityObjectHomepage($object, $hints);
     if (!empty($homepage)) {
         $profile->homepage = $homepage;
     }
     if (!empty($object->geopoint)) {
         $location = ActivityContext::locationFromPoint($object->geopoint);
         if (!empty($location)) {
             $profile->lat = $location->lat;
             $profile->lon = $location->lon;
         }
     }
     // @todo FIXME: tags/categories
     // @todo tags from categories
     if ($profile->id) {
         common_log(LOG_DEBUG, "Updating OStatus profile {$profile->id} from remote info {$object->id}: " . var_export($object, true) . var_export($hints, true));
         $profile->update($orig);
     }
 }
Exemplo n.º 9
0
*/
include '../inc/includes.php';
Session::checkRight("profile", READ);
if (!isset($_GET['id'])) {
    $_GET['id'] = "";
}
$prof = new Profile();
if (isset($_POST["add"])) {
    $prof->check(-1, CREATE, $_POST);
    $ID = $prof->add($_POST);
    // We need to redirect to form to enter rights
    Html::redirect($CFG_GLPI["root_doc"] . "/front/profile.form.php?id={$ID}");
} else {
    if (isset($_POST["purge"])) {
        $prof->check($_POST['id'], PURGE);
        if ($prof->delete($_POST, 1)) {
            $prof->redirectToList();
        } else {
            Html::back();
        }
    } else {
        if (isset($_POST["update"]) || isset($_POST["interface"])) {
            $prof->check($_POST['id'], UPDATE);
            $prof->update($_POST);
            Html::back();
        }
    }
}
Html::header(Profile::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "admin", "profile");
$prof->display(array('id' => $_GET["id"]));
Html::footer();
Exemplo n.º 10
0
<?php

require_once 'classes/profile.php';
$profile = new Profile();
if (isset($_POST['profile_edit'])) {
    // is user allowed to edit this data?
    $data['first_name'] = $_POST['first_name'];
    // secure
    $data['last_name'] = $_POST['last_name'];
    // secure
    $data['facebook'] = $_POST['facebook'];
    // secure
    $data['twitter'] = $_POST['twitter'];
    // secure
    $data['location'] = $_POST['location'];
    // secure
    $data['homepage'] = $_POST['homepage'];
    // secure
    $data['biography'] = $_POST['biography'];
    // secure
    $data['privacy'] = $_POST['privacy'];
    $profile->update($data, $_SESSION['userid']);
    $msg = 'You have updated your profile.';
}
if ($_GET['action'] == 'confirm_email') {
    // do something
}
 public static function createFirstAccess($ID)
 {
     $talk_profile = new self();
     $profile = new Profile();
     $dataprofile = array('id' => $ID);
     $profile->getFromDB($ID);
     foreach ($talk_profile->getAllRights(true) as $talk_r) {
         $g_rights = $profile->getRightsFor($talk_r['itemtype']);
         foreach ($g_rights as $g_right => $label) {
             $dataprofile['_' . $talk_r['field']][$g_right . "_0"] = 1;
         }
     }
     $profile->update($dataprofile);
 }
Exemplo n.º 12
0
 function handle($args)
 {
     parent::handle($args);
     if (common_logged_in()) {
         $this->clientError(_('You can use the local subscription!'));
         return;
     }
     $omb = $_SESSION['oauth_authorization_request'];
     if (!$omb) {
         $this->clientError(_('Not expecting this response!'));
         return;
     }
     common_debug('stored request: ' . print_r($omb, true), __FILE__);
     common_remove_magic_from_request();
     $req = OAuthRequest::from_request();
     $token = $req->get_parameter('oauth_token');
     # I think this is the success metric
     if ($token != $omb['token']) {
         $this->clientError(_('Not authorized.'));
         return;
     }
     $version = $req->get_parameter('omb_version');
     if ($version != OMB_VERSION_01) {
         $this->clientError(_('Unknown version of OMB protocol.'));
         return;
     }
     $nickname = $req->get_parameter('omb_listener_nickname');
     if (!$nickname) {
         $this->clientError(_('No nickname provided by remote server.'));
         return;
     }
     $profile_url = $req->get_parameter('omb_listener_profile');
     if (!$profile_url) {
         $this->clientError(_('No profile URL returned by server.'));
         return;
     }
     if (!Validate::uri($profile_url, array('allowed_schemes' => array('http', 'https')))) {
         $this->clientError(_('Invalid profile URL returned by server.'));
         return;
     }
     if ($profile_url == common_local_url('showstream', array('nickname' => $nickname))) {
         $this->clientError(_('You can use the local subscription!'));
         return;
     }
     common_debug('listenee: "' . $omb['listenee'] . '"', __FILE__);
     $user = User::staticGet('nickname', $omb['listenee']);
     if (!$user) {
         $this->clientError(_('User being listened to doesn\'t exist.'));
         return;
     }
     $other = User::staticGet('uri', $omb['listener']);
     if ($other) {
         $this->clientError(_('You can use the local subscription!'));
         return;
     }
     $fullname = $req->get_parameter('omb_listener_fullname');
     $homepage = $req->get_parameter('omb_listener_homepage');
     $bio = $req->get_parameter('omb_listener_bio');
     $location = $req->get_parameter('omb_listener_location');
     $avatar_url = $req->get_parameter('omb_listener_avatar');
     list($newtok, $newsecret) = $this->access_token($omb);
     if (!$newtok || !$newsecret) {
         $this->clientError(_('Couldn\'t convert request tokens to access tokens.'));
         return;
     }
     # XXX: possible attack point; subscribe and return someone else's profile URI
     $remote = Remote_profile::staticGet('uri', $omb['listener']);
     if ($remote) {
         $exists = true;
         $profile = Profile::staticGet($remote->id);
         $orig_remote = clone $remote;
         $orig_profile = clone $profile;
         # XXX: compare current postNotice and updateProfile URLs to the ones
         # stored in the DB to avoid (possibly...) above attack
     } else {
         $exists = false;
         $remote = new Remote_profile();
         $remote->uri = $omb['listener'];
         $profile = new Profile();
     }
     $profile->nickname = $nickname;
     $profile->profileurl = $profile_url;
     if (!is_null($fullname)) {
         $profile->fullname = $fullname;
     }
     if (!is_null($homepage)) {
         $profile->homepage = $homepage;
     }
     if (!is_null($bio)) {
         $profile->bio = $bio;
     }
     if (!is_null($location)) {
         $profile->location = $location;
     }
     if ($exists) {
         $profile->update($orig_profile);
     } else {
         $profile->created = DB_DataObject_Cast::dateTime();
         # current time
         $id = $profile->insert();
         if (!$id) {
             $this->serverError(_('Error inserting new profile'));
             return;
         }
         $remote->id = $id;
     }
     if ($avatar_url) {
         if (!$this->add_avatar($profile, $avatar_url)) {
             $this->serverError(_('Error inserting avatar'));
             return;
         }
     }
     $remote->postnoticeurl = $omb['post_notice_url'];
     $remote->updateprofileurl = $omb['update_profile_url'];
     if ($exists) {
         if (!$remote->update($orig_remote)) {
             $this->serverError(_('Error updating remote profile'));
             return;
         }
     } else {
         $remote->created = DB_DataObject_Cast::dateTime();
         # current time
         if (!$remote->insert()) {
             $this->serverError(_('Error inserting remote profile'));
             return;
         }
     }
     if ($user->hasBlocked($profile)) {
         $this->clientError(_('That user has blocked you from subscribing.'));
         return;
     }
     $sub = new Subscription();
     $sub->subscriber = $remote->id;
     $sub->subscribed = $user->id;
     $sub_exists = false;
     if ($sub->find(true)) {
         $sub_exists = true;
         $orig_sub = clone $sub;
     } else {
         $sub_exists = false;
         $sub->created = DB_DataObject_Cast::dateTime();
         # current time
     }
     $sub->token = $newtok;
     $sub->secret = $newsecret;
     if ($sub_exists) {
         $result = $sub->update($orig_sub);
     } else {
         $result = $sub->insert();
     }
     if (!$result) {
         common_log_db_error($sub, $sub_exists ? 'UPDATE' : 'INSERT', __FILE__);
         $this->clientError(_('Couldn\'t insert new subscription.'));
         return;
     }
     # Notify user, if necessary
     mail_subscribe_notify_profile($user, $profile);
     # Clear the data
     unset($_SESSION['oauth_authorization_request']);
     # If we show subscriptions in reverse chron order, this should
     # show up close to the top of the page
     common_redirect(common_local_url('subscribers', array('nickname' => $user->nickname)));
 }
Exemplo n.º 13
0
 public function save()
 {
     // check if data posted
     $fields = $this->request['params']['profile'];
     // check errors
     $errors = [];
     $required = ['name', 'city', 'city_feed', 'professions'];
     foreach ($required as $r) {
         if (empty($fields[$r])) {
             $errors[] = $r;
         }
     }
     // update if no errors
     if (empty($errors)) {
         if (Profile::update($fields)) {
             // tell the application to refresh the session data
             Auth::updateUser();
             die(json_encode(array('success' => true, 'msg' => "Your profile is all set!")));
         }
         // update went wrong, show errors
         die(json_encode(array('success' => false, 'error' => $errors)));
     }
     // form errors! back to signup form
     die(json_encode(array('success' => false, 'error' => $errors)));
 }
Exemplo n.º 14
0
<?php

/**
 * Created by PhpStorm.
 * User: OldManVin
 * Date: 1/22/2016
 * Time: 12:01 PM
 */
require_once "/etc/apache2/capstone-mysql/encrypted -config.php";
$pdo = connectToEncryptedMySQL("/ect/apache2/data-design/dfontaine1/ini");
require_once "/etc/apache2/capstone-mysql/encrypted-config.php";
require_once "your-class-file.php";
//now use the PDO object normally
$tweet = new Profile(null, 1, "this is from php");
$tweet->insert($pdo);
$tweet->setProfile("now i change the message");
$tweet->update($pdo);
$tweet->delete($pdo);
Exemplo n.º 15
0
/**
 * Update helpdesk_item_type in a profile if a ProfileRight changes or is created
 * 
 * Add or remove simcard item type to match the status of "associable to tickets" in simcard's right
 * 
 * @since 1.4.1
 */
function plugin_simcard_profileRightUpdate($item)
{
    if ($item->fields['name'] == PluginSimcardProfile::RIGHT_SIMCARD_SIMCARD) {
        $profile = new Profile();
        $profile->getFromDB($item->fields['profiles_id']);
        $helpdeskItemTypes = json_decode($profile->fields['helpdesk_item_type'], true);
        $index = array_search('PluginSimcardSimcard', $helpdeskItemTypes);
        if ($item->fields['rights'] & PluginSimcardProfile::SIMCARD_ASSOCIATE_TICKET) {
            if ($index === false) {
                $helpdeskItemTypes[] = 'PluginSimcardSimcard';
                if ($_SESSION['glpiactiveprofile']['id'] == $profile->fields['id']) {
                    $_SESSION['glpiactiveprofile']['helpdesk_item_type'][] = 'PluginSimcardSimcard';
                }
            }
        } else {
            if ($index !== false) {
                unset($helpdeskItemTypes[$index]);
                if ($_SESSION['glpiactiveprofile']['id'] == $profile->fields['id']) {
                    // Just in case this is not the same index in the session vars
                    $index = array_search('PluginSimcardSimcard', $_SESSION['glpiactiveprofile']['helpdesk_item_type']);
                    if ($index !== false) {
                        unset($_SESSION['glpiactiveprofile']['helpdesk_item_type'][$index]);
                    }
                }
            }
        }
        $tmp = array('id' => $profile->fields['id'], 'helpdesk_item_type' => json_encode($helpdeskItemTypes));
        $profile->update($tmp, false);
    }
}
Exemplo n.º 16
0
 /**
  * Save passed profile
  *
  * Stores the OMB profile $profile. Overwrites an existing entry.
  * Throws exceptions in case of error.
  *
  * @param OMB_Profile $profile   The OMB profile which should be saved
  *
  * @access public
  **/
 public function saveProfile($omb_profile)
 {
     if (common_profile_url($omb_profile->getNickname()) == $omb_profile->getProfileURL()) {
         throw new Exception('Not implemented');
     } else {
         $remote = Remote_profile::staticGet('uri', $omb_profile->getIdentifierURI());
         if ($remote) {
             $exists = true;
             $profile = Profile::staticGet($remote->id);
             $orig_remote = clone $remote;
             $orig_profile = clone $profile;
             // XXX: compare current postNotice and updateProfile URLs to the ones
             // stored in the DB to avoid (possibly...) above attack
         } else {
             $exists = false;
             $remote = new Remote_profile();
             $remote->uri = $omb_profile->getIdentifierURI();
             $profile = new Profile();
         }
         $profile->nickname = $omb_profile->getNickname();
         $profile->profileurl = $omb_profile->getProfileURL();
         $fullname = $omb_profile->getFullname();
         $profile->fullname = is_null($fullname) ? '' : $fullname;
         $homepage = $omb_profile->getHomepage();
         $profile->homepage = is_null($homepage) ? '' : $homepage;
         $bio = $omb_profile->getBio();
         $profile->bio = is_null($bio) ? '' : $bio;
         $location = $omb_profile->getLocation();
         $profile->location = is_null($location) ? '' : $location;
         if ($exists) {
             $profile->update($orig_profile);
         } else {
             $profile->created = DB_DataObject_Cast::dateTime();
             # current time
             $id = $profile->insert();
             if (!$id) {
                 // TRANS: Exception thrown when creating a new profile fails in OAuth store.
                 throw new Exception(_('Error inserting new profile.'));
             }
             $remote->id = $id;
         }
         $avatar_url = $omb_profile->getAvatarURL();
         if ($avatar_url) {
             if (!$this->add_avatar($profile, $avatar_url)) {
                 // TRANS: Exception thrown when creating a new avatar fails in OAuth store.
                 throw new Exception(_('Error inserting avatar.'));
             }
         } else {
             $avatar = $profile->getOriginalAvatar();
             if ($avatar) {
                 $avatar->delete();
             }
             $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
             if ($avatar) {
                 $avatar->delete();
             }
             $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
             if ($avatar) {
                 $avatar->delete();
             }
             $avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
             if ($avatar) {
                 $avatar->delete();
             }
         }
         if ($exists) {
             if (!$remote->update($orig_remote)) {
                 // TRANS: Exception thrown when updating a remote profile fails in OAuth store.
                 throw new Exception(_('Error updating remote profile.'));
             }
         } else {
             $remote->created = DB_DataObject_Cast::dateTime();
             # current time
             if (!$remote->insert()) {
                 // TRANS: Exception thrown when creating a remote profile fails in OAuth store.
                 throw new Exception(_('Error inserting remote profile.'));
             }
         }
     }
 }
Exemplo n.º 17
0
$title = $profile["name"];
//Change page title to user's name
#####################################################
/**
 * Processes all of the page's form submissions
 */
//If the user is trying to follow the profile
if ($_GET["action"] == 'change_relationship') {
    $Profile->changeRelationship($profile["id"], $user["id"]);
    header('Location: profile.php?id=' . $profile["id"]);
    //Redirect to prevent form resubmission
}
//Process the update profile form
if (isset($_POST["edit_profile"])) {
    try {
        $Profile->update($_POST["description_text"], 'description');
        //The user's description
        $Profile->update($_POST["gender"], 'gender');
        //The user's gender
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    header("Location: " . $_SERVER["REQUEST_URI"]);
    //Redirect to prevent form resubmission
}
//Process the upload profile image form
if (isset($_POST["upload_profile_pic"])) {
    if (isset($_FILES['default-image'])) {
        $Image = new Image($Database);
        $Image->uploadTo = $baseDir . 'images/profiles/';
        $uploadedImage = $Image->upload($_FILES['default-image']);
Exemplo n.º 18
0
 static function install(Migration $migration)
 {
     global $DB;
     $profileRight = new ProfileRight();
     $profile = new Profile();
     //Update needed
     if (TableExists('glpi_plugin_genericobject_profiles')) {
         foreach (getAllDatasFromTable('glpi_plugin_genericobject_profiles') as $right) {
             if (preg_match("/PluginGenericobject(.*)/", $right['itemtype'], $results)) {
                 $newrightname = 'plugin_genericobject_' . strtolower($results[1]) . 's';
                 if (!countElementsInTable('glpi_profilerights', "`profiles_id`='" . $right['profiles_id'] . "' \n                                           AND `name`='{$newrightname}'")) {
                     switch ($right['right']) {
                         case NULL:
                         case '':
                             $rightvalue = 0;
                             break;
                         case 'r':
                             $rightvalue = READ;
                             break;
                         case 'w':
                             $rightvalue = ALLSTANDARDRIGHT;
                             break;
                     }
                     $profileRight->add(array('profiles_id' => $right['profiles_id'], 'name' => $newrightname, 'rights' => $rightvalue));
                     if (!countElementsInTable('glpi_profilerights', "`profiles_id`='" . $right['profiles_id'] . "' \n                                              AND `name`='plugin_genericobject_types'")) {
                         $profileRight->add(array('profiles_id' => $right['profiles_id'], 'name' => 'plugin_genericobject_types', 'rights' => 23));
                     }
                 }
                 if ($right['open_ticket']) {
                     $profile->getFromDB($right['profiles_id']);
                     $helpdesk_item_types = json_decode($profile->fields['helpdesk_item_type'], true);
                     if (is_array($helpdesk_item_types)) {
                         if (!in_array($right['itemtype'], $helpdesk_item_types)) {
                             $helpdesk_item_types[] = $right['itemtype'];
                         }
                     } else {
                         $helpdesk_item_types = array($right['itemtype']);
                     }
                     $tmp['id'] = $profile->getID();
                     $tmp['helpdesk_item_type'] = json_encode($helpdesk_item_types);
                     $profile->update($tmp);
                 }
             }
         }
         //$migration->dropTable('glpi_plugin_genericobject_profiles');
     }
     if (!countElementsInTable('glpi_profilerights', "`name` LIKE '%genericobject%'")) {
         self::createFirstAccess();
     }
 }
Exemplo n.º 19
0
 function saveRemoteProfile(&$req)
 {
     # FIXME: we should really do this when the consumer comes
     # back for an access token. If they never do, we've got stuff in a
     # weird state.
     $nickname = $req->get_parameter('omb_listenee_nickname');
     $fullname = $req->get_parameter('omb_listenee_fullname');
     $profile_url = $req->get_parameter('omb_listenee_profile');
     $homepage = $req->get_parameter('omb_listenee_homepage');
     $bio = $req->get_parameter('omb_listenee_bio');
     $location = $req->get_parameter('omb_listenee_location');
     $avatar_url = $req->get_parameter('omb_listenee_avatar');
     $listenee = $req->get_parameter('omb_listenee');
     $remote = Remote_profile::staticGet('uri', $listenee);
     if ($remote) {
         $exists = true;
         $profile = Profile::staticGet($remote->id);
         $orig_remote = clone $remote;
         $orig_profile = clone $profile;
     } else {
         $exists = false;
         $remote = new Remote_profile();
         $remote->uri = $listenee;
         $profile = new Profile();
     }
     $profile->nickname = $nickname;
     $profile->profileurl = $profile_url;
     if (!is_null($fullname)) {
         $profile->fullname = $fullname;
     }
     if (!is_null($homepage)) {
         $profile->homepage = $homepage;
     }
     if (!is_null($bio)) {
         $profile->bio = $bio;
     }
     if (!is_null($location)) {
         $profile->location = $location;
     }
     if ($exists) {
         $profile->update($orig_profile);
     } else {
         $profile->created = DB_DataObject_Cast::dateTime();
         # current time
         $id = $profile->insert();
         if (!$id) {
             return false;
         }
         $remote->id = $id;
     }
     if ($exists) {
         if (!$remote->update($orig_remote)) {
             return false;
         }
     } else {
         $remote->created = DB_DataObject_Cast::dateTime();
         # current time
         if (!$remote->insert()) {
             return false;
         }
     }
     if ($avatar_url) {
         if (!$this->addAvatar($profile, $avatar_url)) {
             return false;
         }
     }
     $user = common_current_user();
     $datastore = omb_oauth_datastore();
     $consumer = $this->getConsumer($datastore, $req);
     $token = $this->getToken($datastore, $req, $consumer);
     $sub = new Subscription();
     $sub->subscriber = $user->id;
     $sub->subscribed = $remote->id;
     $sub->token = $token->key;
     # NOTE: request token, not valid for use!
     $sub->created = DB_DataObject_Cast::dateTime();
     # current time
     if (!$sub->insert()) {
         return false;
     }
     return true;
 }