Dokeos PHP Cross Reference Learning Management Systems

Source: /main/metadata/importlinks.php - 358 lines - 12269 bytes - Summary - Text - Print

   1  <?php /*                                <!-- Dokeos metadata/importlinks.php -->
   2                                                               <!-- 2006/12/15 -->
   3  
   4  <!-- Copyright (C) 2006 rene.haentjens@UGent.be -  see metadata/md_funcs.php -->
   5  
   6  */
   7  
   8  /**
   9  ==============================================================================
  10  *    Dokeos Metadata: create table entries for a category of Link-type items
  11  *
  12  *    @package dokeos.metadata
  13  ==============================================================================
  14  */
  15  
  16  
  17  // PRELIMS -------------------------------------------------------------------->
  18  
  19  $getpostvars = array('lcn', 'slo'); require ('md_funcs.php');
  20  
  21  define('EID_TYPE', 'Link');
  22  define('OF_EID_TYPE', "eid LIKE '" . EID_TYPE . ".%'");
  23  
  24  require('md_' . strtolower(EID_TYPE) . '.php');
  25  
  26  // name of the language file that needs to be included
  27  $language_file = 'md_' . strtolower(EID_TYPE);
  28  include ('../inc/global.inc.php');
  29  $nameTools = get_lang('Tool');
  30  
  31  ($nameTools && get_lang('Sorry')) or give_up(
  32      'Language file ' . $language_file . " doesn't define 'Tool' and 'Sorry'");
  33  
  34  $_course = api_get_course_info(); isset($_course) or give_up(get_lang('Sorry'));
  35  
  36  $is_allowed_to_edit = isset($_user['user_id']) && $is_courseMember && is_allowed_to_edit();
  37  if (!$is_allowed_to_edit) give_up(get_lang('Denied'));
  38  
  39  $mdStore = new mdstore($is_allowed_to_edit);  // create table if needed
  40  
  41  require(api_get_path(LIBRARY_PATH) . 'xmd.lib.php');
  42  require(api_get_path(LIBRARY_PATH) . 'xht.lib.php');
  43  
  44  require ('md_phpdig.php');
  45  
  46  $mdObj = new mdobject($_course, 0);
  47  $mdCat = $mdObj->mdo_dcmap_v['Coverage'];
  48  $mdUrl = 'metadata/lom/technical/location[1]';
  49  
  50  $mdObj->mdo_add_breadcrump_nav();  // see 'md_' . EID_TYPE . '.php'
  51  
  52  $htmldecode = array_flip(get_html_translation_table(HTML_SPECIALCHARS));
  53  
  54  
  55  function check_andor_get($row, $get = '', $check = '', $tobe = '')
  56  {
  57      global $mdCat, $htmldecode;
  58  
  59      if (!$check && !$get) return FALSE;
  60  
  61      $regs = array(); // for use with ereg()
  62  
  63      if ($get == $mdCat && !$check)  // cheat to be quicker
  64          if (ereg('<coverage>[^<]*<string language="..">([^<]+)<\/string>',
  65              $row['mdxmltext'], $regs)) return strtr($regs[1], $htmldecode);
  66  
  67      if ($check == $mdCat && !$get)  // cheat to be quicker
  68          if (ereg('<coverage>[^<]*<string language="..">([^<]+)<\/string>',
  69              $row['mdxmltext'], $regs))
  70                  return (strtr($regs[1], $htmldecode) == $tobe);
  71  
  72      $xmlDoc = new xmddoc(explode("\n", $row['mdxmltext']));
  73      if ($xmlDoc->error) return FALSE;
  74  
  75      if (!$check) return $xmlDoc->xmd_value($get);
  76  
  77      if ($xmlDoc->xmd_value($check) == $tobe)
  78          return $get ? $xmlDoc->xmd_value($get) : TRUE;
  79  
  80      return FALSE;
  81  }
  82  
  83  
  84  function get_cat($catname)
  85  {
  86      global $_course; $cateq = "category_title='". addslashes($catname) . "'";
  87  
  88      $linkcat_table = Database::get_course_table(TABLE_LINK_CATEGORY);
  89      $result = Database::query("SELECT id FROM $linkcat_table WHERE " . $cateq, __FILE__, __LINE__);
  90  
  91      if (Database::num_rows($result) >= 1 && ($row = Database::fetch_array($result)))
  92          return $row['id'];  // several categories with same name: take first
  93  
  94      return FALSE;
  95  }
  96  
  97  
  98  // SET CURRENT LINKS CATEGORY - HEADER ---------------------------------------->
  99  
 100  unset($lci);  // category-id
 101  
 102  if (isset($lcn))  // category_title
 103  {
 104      $lcn = substr(ereg_replace("[^\x20-\x7E\xA1-\xFF]", "", $lcn), 0, 255);
 105  
 106      $uceids = array(); $mceids = array();
 107  
 108      $result = $mdStore->mds_get_many('eid,mdxmltext', OF_EID_TYPE);
 109  
 110      while ($row = Database::fetch_array($result))
 111          if (check_andor_get($row, '', $mdCat, $lcn)) $uceids[] = $row['eid'];
 112  
 113      if (($lci = get_cat($lcn)) !== FALSE)
 114      {
 115          $link_table = Database::get_course_table(TABLE_LINK);
 116          $result = Database::query("SELECT id FROM $link_table WHERE category_id=" . $lci, __FILE__, __LINE__);
 117  
 118          while ($row = Database::fetch_array($result))
 119          {
 120              $lceids[$id = (int) $row['id']] = ($eid = EID_TYPE . '.' . $id);
 121  
 122              if (in_array($eid, $uceids)) $mceids[] = $eid;
 123          }
 124  
 125          $hdrInfo = ' ' . get_lang('WorkOn') . ' ' . htmlspecialchars($lcn, ENT_QUOTES, $charset) .
 126              ', LC-id=&nbsp;' . htmlspecialchars($lci, ENT_QUOTES, $charset);
 127      }
 128      elseif ($lcn)
 129      {
 130          $hdrInfo = ' (' . htmlspecialchars($lcn, ENT_QUOTES, $charset) .
 131              ': ' . get_lang('NotInDB') . ')';
 132      }
 133      else
 134          unset($lcn);
 135  
 136      $uceids = array_diff($uceids, $mceids);  // old entries with no link
 137  
 138      if (count($lceids) && count($uceids))
 139      {
 140          $mdStore->mds_delete_many($uceids); $ufos = Database::affected_rows();
 141      }
 142  
 143      $interbreadcrumb[]= array(
 144          'url' => api_get_self() . '?lcn=' . urlencode($lcn),
 145          'name'=> get_lang('Continue') . ' ' . htmlspecialchars($lcn, ENT_QUOTES, $charset));
 146  }
 147  
 148  $htmlHeadXtra[] = '
 149  <link rel="stylesheet" type="text/css" href="md_styles.css">
 150  <script type="text/javascript" src="md_script.js"></script>
 151  ';
 152  Display::display_header($nameTools);
 153  
 154  // OPERATIONS ----------------------------------------------------------------->
 155  
 156  if ($ufos) echo '<h3>', $ufos, ' ', get_lang('RemainingFor'), ' ',
 157          htmlspecialchars($lcn, ENT_QUOTES, $charset), '</h3>', "\n";
 158  
 159  if (isset($slo)) echo '<h3>', $slo, '</h3>', "\n";  // selected links op
 160  
 161  if (isset($slo))
 162  if ($slo == get_lang('Create') && count($lceids))
 163  {
 164      foreach ($lceids as $id => $eid)
 165      {
 166          $mdObj = new mdobject($_course, $id); $xht = $mdObj->mdo_define_htt();
 167          $mdStore->mds_put($eid, $mdt = $mdObj->mdo_generate_default_xml_metadata(),
 168              'mdxmltext', '?');
 169          $xht->xht_xmldoc = new xmddoc(explode("\n", $mdt));
 170          $mdStore->mds_put($eid, $xht->xht_fill_template('INDEXABLETEXT'),
 171              'indexabletext');
 172          echo '<span class="lbs" onClick="', "javascript: makeWindow('index.php?eid=",
 173              urlencode($eid), "', '', '')\">", htmlspecialchars($eid, ENT_QUOTES, $charset), '</span> ';
 174      }
 175      echo '<br>';
 176  }
 177  elseif ($slo == get_lang('Remove') && count($lceids))
 178  {
 179      $mdStore->mds_delete_many($mceids); $aff = Database::affected_rows();
 180  
 181      echo $aff, ' MDEs/ ', count($lceids), ' ', get_lang('MdCallingTool'),
 182          '<br><br><b>', get_lang('AllRemovedFor'),
 183          ' ', htmlspecialchars($lcn, ENT_QUOTES, $charset), '</b><br />';
 184  }
 185  elseif ($slo == get_lang('Remove') && count($mceids))  // obsolete category
 186  {
 187      $mdStore->mds_delete_many($mceids);
 188  
 189      echo get_lang('AllRemovedFor'), ' ', htmlspecialchars($lcn, ENT_QUOTES, $charset), '<br />';
 190  }
 191  elseif ($slo == get_lang('Index') && file_exists($phpDigIncCn) && count($mceids))
 192  {
 193      $result = $mdStore->mds_get_many('eid,mdxmltext,indexabletext',
 194          OF_EID_TYPE . " AND eid IN ('" .
 195          implode("','", array_map('addslashes', $mceids)) . "')");
 196  
 197      while ($row = Database::fetch_array($result))  // load indexabletexts in memory
 198          $idt[check_andor_get($row, $mdUrl)] = $row['indexabletext'];
 199  
 200      require($phpDigIncCn);  // switch to PhpDig DB
 201  
 202      foreach ($idt as $url => $text)
 203      {
 204          $pu = parse_url($url);
 205          if (!isset($pu['scheme'])) $pu['scheme'] = "http";
 206  
 207          if (isset($pu['host']))
 208          {
 209              $url = $pu['scheme'] . "://" . $pu['host'] . "/"; $file = '';
 210  
 211              if (($path = $pu['path']))
 212              if (substr($path, -1) == '/') $path = substr($path, 1);
 213              else
 214              {
 215                  $pi = pathinfo($path); $path = $pi['dirname'];
 216                  if ($path{0} == '\\') $path = substr($path, 1);
 217                  if ($path{0} == '/')  $path = substr($path, 1) . '/';
 218  
 219                  $file = $pi['basename'];
 220              }
 221  
 222              $file .= ($pu['query'] ? '?'.$pu['query'] : '') .
 223                      ($pu['fragment'] ? '#'.$pu['fragment'] : '');
 224  
 225  
 226              if ($site_id = remove_engine_entries($url, $path, $file))
 227              {
 228                  echo '<table>', "\n";
 229                  index_words($site_id, $path, $file,
 230                      get_first_words($text, $url . $path, $file),
 231                      get_keywords($text));
 232                  echo '</table>', "\n";
 233              }
 234              else
 235              {
 236                  echo '<table>', "\n";
 237                  echo '<tr><td>', htmlspecialchars($url, ENT_QUOTES, $charset),
 238                      '</td><td>', htmlspecialchars($path, ENT_QUOTES, $charset),
 239                      '</td><td>', htmlspecialchars($file, ENT_QUOTES, $charset), '</td></tr>';
 240                  echo '</table>', "\n";
 241              }
 242          }
 243          elseif (isset($pu['scheme']) && $pu['scheme'] == 'mailto' && isset($pu['path']))
 244          {
 245              if ($site_id = remove_engine_entries($url = 'mailto:' . $pu['path'], ''))
 246              {
 247                  echo '<table>', "\n";
 248                  index_words($site_id, '', '',
 249                      get_first_words($text, $url, ''),
 250                      get_keywords($text));
 251                  echo '</table>', "\n";
 252              }
 253              else
 254              {
 255                  echo '<table>', "\n";
 256                  echo '<tr><td>', htmlspecialchars($url, ENT_QUOTES, $charset),
 257                      '</td><td>', htmlspecialchars($path, ENT_QUOTES, $charset),
 258                      '</td><td>', htmlspecialchars($file, ENT_QUOTES, $charset), '</td></tr>';
 259                  echo '</table>', "\n";
 260              }
 261          }
 262      }
 263  
 264      if(isset($db))
 265      {
 266          mysql_select_db($_configuration['main_database'], $db);  // back to Dokeos
 267      }
 268  }
 269  elseif ($slo == get_lang('Index'))
 270  {
 271      echo 'Problem! PhpDig connect.php has gone ...';
 272  }
 273  
 274  
 275  // STATISTICS ----------------------------------------------------------------->
 276  
 277  echo '<h3>', get_lang('Statistics'), '</h3>', "\n";
 278  
 279  $result = $mdStore->mds_get_many('eid,mdxmltext', OF_EID_TYPE);
 280  echo get_lang('TotalMDEs'), Database::num_rows($result), "\n";
 281  
 282  while ($row = Database::fetch_array($result))
 283  {
 284      $cat = check_andor_get($row, $mdCat);
 285      $perCat[$cat] = ($pc = $perCat[$cat]) ? $pc + 1 : 1;
 286  }
 287  
 288  if (count($perCat))
 289  {
 290      echo '<table>', "\n";
 291      foreach ($perCat as $cat => $number)
 292      {
 293          echo '<tr><td>', $cat == $lcn ? '' : '(', htmlspecialchars($cat, ENT_QUOTES, $charset),
 294              $cat == $lcn ? '' : ')', ':</td><td align="right">',
 295              $number, '</td></tr>', "\n";
 296      }
 297      echo '</table>', "\n";
 298  }
 299  
 300  if (isset($lci))
 301  {
 302      echo '<br><br>', htmlspecialchars($lcn, ENT_QUOTES, $charset), ' ', get_lang('MdCallingTool'),
 303          ': ', count($lceids), '<br />', "\n";
 304  }
 305  
 306  
 307  
 308  // SELECT & FOOTER ------------------------------------------------------------>
 309  
 310  echo '<h3>', $nameTools, $hdrInfo, '</h3>', "\n";
 311  
 312  echo '<form action="' .api_get_self(). '?lcn=' . urlencode($lcn) .
 313      '" method="post">', "\n";
 314  
 315  if (count($lceids)) echo
 316      '<input type="submit" name="slo" value="', get_lang('Create'), '">', "\n";
 317  if ($perCat[$lcn]) echo
 318      '<input type="submit" name="slo" value="', get_lang('Remove'), '">', "\n";
 319  if ($perCat[$lcn] && file_exists($phpDigIncCn)) echo
 320      '<input type="submit" name="slo" value="', get_lang('Index'), '">', "\n";
 321  
 322  echo '</form>', "\n";
 323  
 324  if (count($perCat)) foreach ($perCat as $cat => $number)
 325      $perCat[$cat] = '(' . htmlspecialchars($cat, ENT_QUOTES, $charset) . ')';
 326  
 327  $linkcat_table = Database::get_course_table(TABLE_LINK_CATEGORY);
 328  $result = Database::query("SELECT category_title FROM $linkcat_table", __FILE__, __LINE__);
 329  
 330  while ($row = Database::fetch_array($result))
 331  {
 332      $cat = $row['category_title']; $hcat = htmlspecialchars($cat, ENT_QUOTES, $charset);
 333      if ($perCat[$cat] == $hcat) $dups[] = $cat;
 334      else $perCat[$cat] = $hcat;
 335  }
 336  
 337  if (count($dups))
 338  {
 339      $warning = get_lang('WarningDups');;
 340  
 341      foreach ($dups as $cat) unset($perCat[$cat]);
 342  }
 343  
 344  echo '<h3>', get_lang('OrElse'), $warning, '</h3>', "\n",  // select new target
 345      '<table><tr><td align="right" class="alternativeBgDark">', "\n",
 346      '<form action="'.api_get_self().'" method="post">', "\n",
 347      get_lang('SLC'), ' :', "\n", '<select name="lcn">', "\n",
 348      '<option value=""></option>', "\n";
 349  
 350      foreach ($perCat as $cat => $text) echo '<option value="' .
 351          htmlspecialchars($cat, ENT_QUOTES, $charset) . '"' .
 352          ($cat == $lcn ? ' selected' : '') . '>' . $text . '</option>', "\n";
 353  
 354  echo '</select><input type="submit" value="', '  '.get_lang('Ok').'  ', '">', "\n",
 355      '</form>', "\n", '</td></tr></table>', "\n";
 356  
 357  Display::display_footer();
 358  ?>

title

Description

title

Description

title

Description

title

title

Body