Example #1
0
function wikiplugin_insert_rewrite($data, $params, $context)
{
    $tikilib = TikiLib::lib('tiki');
    $trackerIds = $tikilib->get_preference('tracker_insert_allowed', array(), true);
    foreach ($trackerIds as $trackerId) {
        $utilities = new Services_Tracker_Utilities();
        $item = Tracker_Item::newItem($trackerId);
        if (!$item->canModify()) {
            continue;
        }
        $definition = $item->getDefinition();
        if (!$definition->canInsert(array_keys($params))) {
            continue;
        }
        $available = array();
        foreach ($params as $key => $value) {
            if ($item->canModifyField($key)) {
                $available[$key] = $value;
            }
        }
        $id = $utilities->insertItem($definition, array('status' => 'o', 'fields' => $available));
        if (false !== $id) {
            $relationlib = TikiLib::lib('relation');
            $relationlib->add_relation('tiki.source.creator', 'trackeritem', $id, $context['type'], $context['itemId']);
            return "{objectlink type=trackeritem id={$id}}";
        }
    }
    return false;
}
Example #2
0
 function write(\Tracker\Tabular\Source\SourceInterface $source)
 {
     $schema = $source->getSchema();
     $definition = $schema->getDefinition();
     $columns = $schema->getColumns();
     $utilities = new \Services_Tracker_Utilities();
     $tx = \TikiDb::get()->begin();
     $lookup = $this->getItemIdLookup($schema);
     foreach ($source->getEntries() as $entry) {
         $info = ['itemId' => false, 'status' => '', 'fields' => []];
         foreach ($columns as $column) {
             $entry->parseInto($info, $column);
         }
         $info['itemId'] = $lookup($info);
         if ($info['itemId']) {
             $utilities->updateItem($definition, $info);
         } else {
             $utilities->insertItem($definition, $info);
         }
     }
     $tx->commit();
 }
Example #3
0
 private function createItem($metadata, $additional)
 {
     $definition = $this->getScormTracker();
     $fields = $this->buildFields($definition, $metadata, $additional);
     $utilities = new Services_Tracker_Utilities();
     $utilities->insertItem($definition, array('status' => 'o', 'fields' => $fields));
 }
Example #4
0
 function linkedInLogin()
 {
     global $user, $prefs;
     $userlib = TikiLib::lib('user');
     $curl = curl_init();
     $data = array("oauth2_access_token" => $_SESSION['LINKEDIN_ACCESS_TOKEN'], "format" => "json");
     $profile_fields = array('id', 'first-name', 'last-name', 'formatted-name', 'picture-url', 'picture-urls::(original)');
     if ($prefs['socialnetworks_linkedin_email'] == 'y') {
         $profile_fields[] = 'email-address';
     }
     $url = "https://api.linkedin.com/v1/people/~:(" . implode(",", $profile_fields) . ")";
     $url = sprintf("%s?%s", $url, http_build_query($data, '', '&'));
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     $result = curl_exec($curl);
     curl_close($curl);
     $linkedin_info = json_decode($result);
     if (isset($linkedin_info->errorCode)) {
         $smarty = TikiLib::lib('smarty');
         $smarty->assign('errortype', 'login');
         $smarty->assign('msg', tra('We were unable to log you in using your LinkedIn account. Please contact the administrator.'));
         $smarty->display('error.tpl');
         die;
     }
     if (!$user) {
         if ($prefs['socialnetworks_linkedin_login'] != 'y') {
             return false;
         }
         $local_user = $this->getOne("select `user` from `tiki_user_preferences` where `prefName` = 'linkedin_id' and `value` = ?", array($linkedin_info->id));
         if ($local_user) {
             $user = $local_user;
         } elseif ($prefs['socialnetworks_linkedin_autocreateuser'] == 'y') {
             $randompass = $userlib->genPass();
             $email = $prefs['socialnetworks_linkedin_email'] === 'y' ? $linkedin_info->emailAddress : '';
             if ($prefs['login_is_email'] == 'y' && $email) {
                 $user = $email;
             } else {
                 if ($prefs['login_autogenerate'] == 'y') {
                     $user = '';
                 } else {
                     $user = '******' . $linkedin_info->id;
                 }
             }
             $user = $userlib->add_user($user, $randompass, $email);
             if (!$user) {
                 $smarty = TikiLib::lib('smarty');
                 $smarty->assign('errortype', 'login');
                 $smarty->assign('msg', tra('We were unable to log you in using your LinkedIn account. Please contact the administrator.'));
                 $smarty->display('error.tpl');
                 die;
             }
             //Checks if user tracker is used and if it is, then set the names as per the info
             $ret = $userlib->get_usertrackerid("Registered");
             $userTracker = $ret['usersTrackerId'];
             $userField = $ret['usersFieldId'];
             if ($prefs['socialnetworks_linkedin_create_user_trackeritem'] == 'y' && $userTracker && $userField) {
                 $definition = Tracker_Definition::get($userTracker);
                 $utilities = new Services_Tracker_Utilities();
                 $fields = array('ins_' . $userField => $user);
                 if (!empty($prefs['socialnetworks_linkedin_names'])) {
                     $names = array_map('trim', explode(',', $prefs['socialnetworks_linkedin_names']));
                     $fields['ins_' . $names[0]] = $linkedin_info->firstName;
                     $fields['ins_' . $names[1]] = $linkedin_info->lastName;
                 }
                 $utilities->insertItem($definition, array('status' => '', 'fields' => $fields, 'validate' => false));
             }
             $this->set_user_preference($user, 'realName', $linkedin_info->formattedName);
             if ($prefs['feature_userPreferences'] == 'y') {
                 $avatarlib = TikiLib::lib('avatar');
                 $avatarlib->set_avatar_from_url($linkedin_info->pictureUrls->values[0], $user);
             }
         } else {
             $_SESSION['loginfrom'] = str_replace('tiki-socialnetworks_linkedin.php', 'tiki-socialnetworks.php', $_SERVER['REQUEST_URI']);
             $smarty = TikiLib::lib('smarty');
             $smarty->assign('errortype', 'login');
             $smarty->assign('msg', tra('You need to link your local account to LinkedIn before you can login using it'));
             $smarty->display('error.tpl');
             die;
         }
         global $user_cookie_site;
         $_SESSION[$user_cookie_site] = $user;
         $userlib->update_expired_groups();
         $this->set_user_preference($user, 'linkedin_id', $linkedin_info->id);
         $this->set_user_preference($user, 'linkedin_token', $_SESSION['LINKEDIN_ACCESS_TOKEN']);
         $userlib->update_lastlogin($user);
         header('Location: tiki-index.php');
         die;
     } else {
         $this->set_user_preference($user, 'linkedin_id', $linkedin_info->id);
         $this->set_user_preference($user, 'linkedin_token', $_SESSION['LINKEDIN_ACCESS_TOKEN']);
     }
     return true;
 }
Example #5
0
 function action_insert_item($input)
 {
     $processedFields = array();
     $trackerId = $input->trackerId->int();
     if (!$trackerId) {
         return ['FORWARD' => ['controller' => 'tracker', 'action' => 'select_tracker']];
     }
     $trackerName = $this->trackerName($trackerId);
     $definition = Tracker_Definition::get($trackerId);
     if (!$definition) {
         throw new Services_Exception_NotFound();
     }
     $itemObject = Tracker_Item::newItem($trackerId);
     if (!$itemObject->canModify()) {
         throw new Services_Exception_Denied();
     }
     $fields = $input->fields->none();
     $forced = $input->forced->none();
     if (empty($fields)) {
         $toRemove = array();
         $processedFields = $itemObject->prepareInput($input);
         $fields = array();
         foreach ($processedFields as $k => $f) {
             $permName = $f['permName'];
             $fields[$permName] = $f['value'];
             if (isset($forced[$permName])) {
                 $toRemove[$permName] = $k;
             }
         }
         foreach ($toRemove as $permName => $key) {
             unset($fields[$permName]);
             unset($processedFields[$key]);
         }
     } else {
         $out = array();
         foreach ($fields as $key => $value) {
             if ($itemObject->canModifyField($key)) {
                 $out[$key] = $value;
             }
         }
         $fields = $out;
     }
     global $prefs;
     if ($prefs['feature_jquery_validation'] === 'y') {
         $validationjs = TikiLib::lib('validators')->generateTrackerValidateJS($definition->getFields());
         TikiLib::lib('header')->add_jq_onready('$("#insertItemForm' . $trackerId . '").validate({' . $validationjs . $this->get_validation_options());
     }
     $itemId = 0;
     if (!empty($fields) && $_SERVER['REQUEST_METHOD'] == 'POST') {
         foreach ($forced as $key => $value) {
             if ($itemObject->canModifyField($key)) {
                 $fields[$key] = $value;
             }
         }
         // test if one item per user
         if ($definition->getConfiguration('oneUserItem', 'n') == 'y') {
             $tmp = TikiLib::lib('trk')->get_user_item($trackerId, $definition->getInformation());
             if ($tmp > 0) {
                 throw new Services_Exception(tr('Item could not be created. Only one item per user is allowed.'), 400);
             }
         }
         $itemId = $this->utilities->insertItem($definition, array('status' => $input->status->word(), 'fields' => $fields));
         if ($itemId) {
             TikiLib::lib('unifiedsearch')->processUpdateQueue();
             TikiLib::events()->trigger('tiki.process.redirect');
             // wait for indexing to complete before loading of next request to ensure updated info shown
             if ($next = $input->next->url()) {
                 $access = TikiLib::lib('access');
                 $access->redirect($next, tr('Item created'));
             }
             $item = $this->utilities->getItem($trackerId, $itemId);
             $item['itemTitle'] = $this->utilities->getTitle($definition, $item);
             return $item;
         } else {
             throw new Services_Exception(tr('Item could not be created.'), 400);
         }
     }
     $editableFields = $input->editable->none();
     if (empty($editableFields)) {
         //if editable fields, show all fields in the form (except the ones from forced which have been removed).
         $displayedFields = $processedFields;
     } else {
         // if editableFields is set, only add the field if found in the editableFields array
         $displayedFields = array();
         foreach ($processedFields as $k => $f) {
             $permName = $f['permName'];
             if (in_array($permName, $editableFields)) {
                 $displayedFields[] = $f;
             }
         }
     }
     $status = $input->status->word();
     if ($status === null) {
         // '=== null' means status was not set. if status is set to "", it skips the status and uses the default
         $status = $itemObject->getDisplayedStatus();
     } else {
         $status = $input->status->word();
     }
     $title = $input->title->none();
     if (empty($title)) {
         // '=== null' means status was not set. if status is set to "", it skips the status and uses the default
         $title = tr('Create Item');
     } else {
         $title = $title;
     }
     return array('title' => $title, 'trackerId' => $trackerId, 'trackerName' => $trackerName, 'itemId' => $itemId, 'fields' => $displayedFields, 'forced' => $forced, 'trackerLogo' => $definition->getConfiguration('logo'), 'modal' => $input->modal->int(), 'status' => $status, 'format' => $input->format->word());
 }