/** * Returns the HTML and JS code for the ratings widget for $bnum * * @param object $user Drupal user object * @param int $bnum Bib number * @param float $rating Rating value override * @param boolean $show_label Displays the vote count * @param boolean $post_redirect Redirect the page back on itself after form submit. Useful for lists. * @return string HTML/JS widget */ function theme_sopac_get_rating_stars($bnum, $rating = NULL, $show_label = TRUE, $post_redirect = FALSE, $id = 'default') { global $user; // Load Required JS libraries drupal_add_js(drupal_get_path('module', 'sopac') . '/js/jquery.rating.js'); $insurge = sopac_get_insurge(); $rate_options = array('0.5', '1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0'); if ($_POST[$id . '_rating_submit_' . $bnum] && $user->uid) { $insurge = sopac_get_insurge(); $insurge->submit_rating($user->uid, $bnum, $_POST[$id . '_bib_rating_' . $bnum]); // Summer Game if (module_exists('summergame')) { if (variable_get('summergame_points_enabled', 0)) { if ($player = summergame_player_load(array('uid' => $user->uid))) { // Check that player has not already rated this item $res = db_query("SELECT lid FROM sg_ledger WHERE pid = %d AND type = 'Rated an Item' " . "AND metadata LIKE '%%bnum:%d' LIMIT 1", $player['pid'], $bnum); $rate_count = db_fetch_object($res); if (!$rate_count->lid) { $points = 10; // Check if the item is in their checkout history $ch_list = db_fetch_object(db_query("SELECT * FROM sopac_lists WHERE uid = %d and title = 'Checkout History'", $user->uid)); if ($ch_list->list_id) { $ch_items = $insurge->get_list_items($ch_list->list_id); foreach ($ch_items as $ch_item) { if ($ch_item['bnum'] == $bnum) { $points = 50; $extra_message = ' from your ' . l('Checkout History', 'user/lists/' . $ch_list->list_id); break; } } } $points = summergame_player_points($player['pid'], $points, 'Rated an Item', 'Added a Rating to the Catalog', 'bnum:' . $bnum); $points_link = l($points . ' Summer Game points', 'summergame/player'); drupal_set_message("Earned {$points_link} for rating an item in the catalog" . $extra_message); } } } } if ($post_redirect) { header('Location: ' . request_uri()); } } if (!$user->uid) { $disable_flag = ' disabled="disabled" '; $login_string = ' - ' . l(t('Login'), 'user/login', array('query' => drupal_get_destination())) . t(' to add yours'); } $ratings_info_arr = $insurge->get_rating($bnum); if ($rating) { $ratings_info_arr['value'] = $rating; } $star_code = ' <script> $(function(){ $(\'.hover-star\').rating({ callback: function(value, link) { this.form.submit(); }, required: true, half: true }); }); </script> <form method="post" name="form_' . $bnum . '"> <table><tr><td width="90px">'; foreach ($rate_options as $val) { $checked_flag = ''; if ((double) $val == (double) $ratings_info_arr['value']) { $checked_flag = ' checked="checked"'; } $star_code .= '<input class="hover-star {split:2}" type="radio" name="' . $id . '_bib_rating_' . $bnum . '" value="' . $val . '"' . $disable_flag . $checked_flag . "/>\n"; } $star_code .= '<input type="hidden" name="' . $id . '_rating_submit_' . $bnum . '" value="1"></form></td><td>'; if ($show_label) { if (!$ratings_info_arr['count']) { $count_msg = t('No ratings yet'); } elseif ($ratings_info_arr['count'] == 1) { $count_msg = '1 rating'; } else { $count_msg = $ratings_info_arr['count'] . t(' ratings'); } $count_msg .= $login_string; $star_code .= '<span id="star_vote_count">(' . $count_msg . ')</span>'; } $star_code .= '</td></tr></table>'; return $star_code; }
function sopac_import_history($list_id, $uid) { $account = user_load($uid); $locum = sopac_get_locum(); $insurge = sopac_get_insurge(); $userinfo = $locum->get_patron_info($account->profile_pref_cardnum); $pnum = $userinfo['pnum']; $res = db_query("SELECT * FROM sopac_history WHERE pnum = %d ORDER BY codate ASC", $pnum); while ($history_item = db_fetch_object($res)) { $insurge->add_list_item($uid, $list_id, $history_item->bnum, strtotime($history_item->codate)); } }
/** * Prepares and returns the HTML for an item record. * Uses the following templates: sopac_record.tpl.php * * @return string Item record HTML */ function sopac_bib_record() { global $user; $locum = sopac_get_locum(); $insurge = sopac_get_insurge(); $actions = sopac_parse_uri(); $bnum = $actions[1]; $getvars = sopac_parse_get_vars(); $output = $getvars['output']; // Load social function require_once 'sopac_social.php'; drupal_add_js('misc/collapse.js'); drupal_add_js(drupal_get_path('theme', 'aadl') . '/soundmanager2-nodebug-jsmin.js'); drupal_add_js(drupal_get_path('theme', 'aadl') . '/inlineplayer.js'); $no_circ = $locum->csv_parser($locum->locum_config['location_limits']['no_request']); $show_inactive = user_access('show suppressed records'); $item = $locum->get_bib_item($bnum, $show_inactive); $bnum_arr[] = $bnum; $reviews = $insurge->get_reviews(NULL, $bnum_arr, NULL); $i = 0; foreach ($reviews['reviews'] as $insurge_review) { $rev_arr[$i]['rev_id'] = $insurge_review['rev_id']; $rev_arr[$i]['bnum'] = $insurge_review['bnum']; if ($insurge_review['uid']) { $rev_arr[$i]['uid'] = $insurge_review['uid']; } $rev_arr[$i]['timestamp'] = $insurge_review['rev_create_date']; $rev_arr[$i]['rev_title'] = $insurge_review['rev_title']; $rev_arr[$i]['rev_body'] = $insurge_review['rev_body']; $i++; } if (!$insurge->check_reviewed($user->uid, $bnum_arr[0]) && $user->uid) { $rev_form = drupal_get_form('sopac_review_form', $bnum_arr[0]); } else { $rev_form = NULL; } if ($machinetags = $insurge->get_machine_tags($bnum)) { foreach ($machinetags as $machinetag) { $item['machinetags'][$machinetag['namespace']][] = $machinetag; } } if (($item['magnatune_url'] || $item['mat_code'] == 'z') && !$item['stream_filetype']) { $result_page = theme('sopac_record_musicdownload', $item, $locum->locum_config, $rev_arr, $rev_form); } else { if ($item['mat_code']) { $item['tracks'] = $locum->get_cd_tracks($bnum); $item['trackupc'] = $locum->get_upc($bnum); if ($item['bnum']) { $item_status = $locum->get_item_status($bnum, TRUE); } // Grab Syndetics reviews, etc.. $review_links = $locum->get_syndetics($item['stdnum'][0]); if (count($review_links)) { $item['review_links'] = $review_links; } $lists = $insurge->get_item_list_ids($item['bnum']); if (count($lists)) { $sql = "SELECT * FROM {sopac_lists} WHERE public = 1 and list_id IN (" . implode($lists, ',') . ") ORDER BY list_id DESC"; $res = db_query($sql); for ($i = 1; $i <= 10; $i++) { $record = db_fetch_array($res); $item['lists'][] = $record; } } // Build the page $result_page = theme('sopac_record', $item, $item_status, $locum->locum_config, $no_circ, &$locum, $rev_arr, $rev_form); } else { $result_page = t('This record does not exist.'); } } if ($output == "rss") { $item['status'] = $item_status; $item['type'] = 'bib'; $cover_img_url = $item['cover_img']; return theme('sopac_results_hitlist_rss', 1, $cover_img_url, $item, $locum->locum_config, $no_circ); } else { return '<p>' . t($result_page) . '</p>'; } }
function sopac_admin_moderate_delete_confirm_submit($form, &$form_state) { $insurge = sopac_get_insurge(); if ($reviews = $form_state['values']['reviews']) { foreach ($reviews as $review) { if (module_exists('summergame')) { if ($player = summergame_player_load(array('uid' => $review['uid']))) { // Delete the points from the player record if found db_query("DELETE FROM sg_ledger WHERE pid = %d AND type = 'Wrote Review' " . "AND metadata LIKE '%%bnum:%d%%'", $player['pid'], $review['bnum']); if (db_affected_rows()) { $player_link = l($points . ' Summer Game score card', 'summergame/player/' . $player['pid']); drupal_set_message("Removed points for this review from player's {$player_link}"); } } } $insurge->delete_review($review['uid'], $review['rev_id']); } drupal_goto('admin/settings/sopac/moderate/reviews'); } else { if ($tags = $form_state['values']['tags']) { if (module_exists('summergame')) { foreach ($tags as $tag) { if ($player = summergame_player_load(array('uid' => $tag['uid']))) { // Delete the points from the player record if found db_query("DELETE FROM sg_ledger WHERE pid = %d AND type = 'Tagged an Item' " . "AND metadata LIKE '%%bnum:%d%%'", $player['pid'], $tag['bnum']); if (db_affected_rows()) { $player_link = l($points . ' Summer Game score card', 'summergame/player/' . $player['pid']); drupal_set_message("Removed points for this tag from player's {$player_link}"); } } $insurge->delete_user_tag($tag['uid'], $tag['tag'], $tag['bnum']); } } drupal_goto('admin/settings/sopac/moderate/tags'); } } }