This file is indexed.

/usr/share/moodle/mod/assignment/type/wims/wimsclass.php is in wims-moodle 4.0-18.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php // $Id: wimsclass.php,v 1.1.1.1 2009-04-04 14:19:23 georgesk Exp $

require_once($CFG->libdir.'/datalib.php'); // for get_record(...)

/**
 * The class wc_data encapsulates the format of the request necessary
 * to create a Wims class.
 * @author: Georges Khaznadar
 *
 * initialisation:  wc_data($rclass,$service,$servicepass)
 * parameters:
 * * $rclass is the name of the class in Moodle
 * * There must be a file wimshome/log/classes/.connections/$service
 * * with a line defining: 'ident_password=$servicepass'
 *
 * an accessor: toString($html=1)
 * this function outputs a string with the object's internals.
 * parameters:
 * $html, when true, fits the output to be displaied in a HTML page.
 *
 * two functions: data1() and data2()
 * these functions prepare the data for the Wims class according to the
 * documentation file http://wims.unice.fr/wims/?module=adm/raw&job=help
 **********************************************************************/

class wc_data{
  var $description;
  var $institution;
  var $firstname;
  var $lastname;
  var $supervisor;
  var $email;
  var $password;
  var $lang;
  var $expiration;
  var $limit;
  var $secure;
  var $qclass;
  var $service;
  var $servicepass;
  function wc_data($assignment,$service,$servicepass){
	global $DB;    
$this->service=$service;
    $this->servicepass=$servicepass;
    $this->description=rclass($assignment);
   // $c1=get_record("course","id",1);
    $c1=$DB->get_record("course",array("id"=>1)); //Recuperation du nom du site moodle

    $this->institution=protection($c1->shortname);
    $context = get_context_instance(CONTEXT_COURSE, $assignment->course);
    $teacherID=3; // 3 is the id for teachers.
    $users = get_role_users($teacherID, $context, true, '', 'u.lastname ASC', true);
    $firstuser=array_shift($users);
    $tid=$firstuser->id;
   // $t=get_record("user","id",$tid);
    $t=$DB->get_record("user",array("id"=>$tid));
    $this->firstname=$t->firstname;
    $this->lastname=$t->lastname;
    $this->supervisor=$t->username;
    $this->email=$t->email;
    $this->password=random_string(8);
    $this->lang=ereg_replace("_.*","",$t->lang);
    $now=time();
    $this->expiration=(date('Y',$now)+1).date('md',$now);
    $this->limit="499";
    $this->secure="all";
    $this->qclass="";
  }
  function toString($html=1){
    if ($html) $spacer="<br />"; else $spacer=" ";
    $result="";
    $result.="description = ".$this->description.$spacer;
    $result.="institution = ".$this->institution.$spacer;
    $result.="firstname = ".$this->firstname.$spacer;
    $result.="lastname = ".$this->lastname.$spacer;
    $result.="supervisor = ".$this->supervisor.$spacer;
    $result.="password = ".$this->password.$spacer;
    $result.="lang = ".$this->lang.$spacer;
    $result.="expiration = ".$this->expiration.$spacer;
    $result.="limit = ".$this->limit.$spacer;
    $result.="secure = ".$this->secure.$spacer;
    return $result;
  }
  function data1(){
    $d1=array('description', 'institution', 'supervisor', 'email', 'password',
	      'lang', 'expiration', 'limit', 'level', 'secure',
	      'bgcolor', 'refcolor', 'css');
    $data1="";
    foreach ($d1 as $d){

     		if (isset($this->$d) && strlen($this->$d)>0){
			$data1.=$d."=".$this->$d."\n";
   		}
	
    }
    return urlencode($data1);
  }
  function data2(){
    $d2=array('lastname', 'firstname', 'useremail', 'comment', 'regnum');
    $data2="";
    foreach ($d2 as $d){
      if (isset($this->$d) && strlen($this->$d)>0){
	$data2.=$d."=".$this->$d."\n";
      }
    }
    $data2.="password=".random_string(8)."\n";// this password will not be used
    return urlencode($data2);
  }
}

/**
 * makes a name for the "Wims class" on Moodle's side
 */

function rclass($assignment){
global $DB; 
 //$c=get_record("course","id",$assignment->course); v1.9 moodle
  $c=$DB->get_record("course",array("id"=>($assignment->course)));
	
  return rclassFromCourseAndModule($c,$assignment);
}

function rclassFromCourseAndModule($c,$m){
  return wimsIconv($c->shortname)."_".wimsIconv($m->name);
}

/**
 * protects a worksheet's contents before calling the job addsheet
 */

function protectSheetContents($contents){
  $contents=str_replace("\n",";",$contents);
  $contents=str_replace("=","@",$contents);
  return $contents;
}

/**
 * the class workSheet encapsulates pentuples (index,title,status,rclass,qclass)
 * AFAIK, the status are the following with WIMS :
 * 0 = in preparation
 * 1 = active worksheet
 * 2 = unactive worksheet
 * 3 = hidden worksheet
 */
class workSheet{
  var $index;
  var $title;
  var $status;
  var $rclass;
  var $qclass;
  var $rclassEnc;

  /**
   * the constructor
   */
  function workSheet($index,$title,$status,$rclass,$qclass){
    $this->index=$index;
    $this->title=$title;
    $this->status=$status;
    $this->rclass=$rclass;
    $this->qclass=$qclass;
    $this->rclassEnc=urlencode($rclass);
  }

  /**
   * @return an url to get the worksheet's file
   * @param $jr : a job_raw object already initialized
   */
  function getUrl($jr){
    $url=$jr->url("getclassfile",
		  "qclass=$this->qclass&rclass=$this->rclassEnc".
		  "&option=sheets/.sheet".$this->index);
    return $url;
  }

  /**
   * @return an url to add the worsheet's contents to
   * a wims assignment's miniclass.
   * @param $assign_wims the wims assignment
   * @param $forbidMD5sums an array of already present md5 sums of contents
   */
  function addsheetToUrl($assign_wims, $forbidMD5sums=array()){
    global $CFG;
	global $DB;
    $contents=$this->contents($assign_wims->jr);
    $md5=md5($contents);
    if (array_intersect($forbidMD5sums,array($md5))) return "";
    $contents=protectSheetContents($contents);
    $qclass=$assign_wims->assignment->var2;
    $course= $DB->get_record("course", array("id"=>$assign_wims->cm->course));
    $rclass=rclassFromCourseAndModule($course, $assign_wims->cm);
    $rclassEnc=urlencode($rclass);
    $parms="qclass=$qclass&rclass=$rclassEnc&data1=" . 
      urlencode("contents=$contents\nsheetmode=3\ntitle=$this->title\n");
    $url=$assign_wims->jr->url("addsheet",$parms);
    return $url;
  }

  /**
   * @return the contents of the worksheet's file
   * @param $jr : a job_raw object already initialized
   */
  function contents($jr){
    global $CFG;
    $url=$this->getUrl($jr);
    $url=urlencode($url);
    $url=$CFG->wwwroot."/mod/assignment/type/wims/getsheetsource.php?url=$url";
    $f=fopen($url,"r");
    if($f){
      $contents=fread($f,20480);
      fclose($f);
    } else {
      $contents="";
    }
    return $contents;
  }
}


/**
 * the class wimsExam encapsulates quadruples (index,title,rclass,qclass)
 * AFAIK, the status are the following with WIMS :
 * 0 = in preparation
 * 1 = active exam
 * 2 = unactive exam
 * 3 = hidden exam
 */
class wimsExam{
  var $index;
  var $i;
  var $title;
  var $rclass;
  var $qclass;
  var $rclassEnc;

  /**
   * the constructor
   */
  function wimsExam($index,$title,$rclass,$qclass){
    $this->index=$index;
    $this->i=substr($index,4,255); // the number after "exam"
    $this->title=$title;
    $this->rclass=$rclass;
    $this->qclass=$qclass;
    $this->rclassEnc=urlencode($rclass);
  }

  function wimsButton($user){
    $result="here should be button to access the exam ".$this->title;
    print "debug user:<pre>";print_r($user->lastname);; print "</pre>";
    return $result;
  }
}

/**
 * converts utf8 strings for WIMS
 * @param s the input string
 * @return a string recoded for Wims
 */

  function wimsIconv($s,$mode="forth"){
      $r=$s;
      $wims_is_not_utf8=TRUE;
      if($wims_is_not_utf8 && function_exists('iconv')){
	if ($mode=="forth") $r=iconv('UTF-8','ISO8859-1',$s);
	else $r=iconv('ISO8859-1','UTF-8',$s); // $mode=='back' for instance
      }
      return protection($r);
  }

/********
 * protects some names which are not allowable as an rclass for Wims
 * @param $s input string
 * @return the protected string
 */
 function protection($s){
   for ($i=0; $i<strlen($s); $i++){
     if (strstr("- ',;.:!=+",$s[$i])) $s[$i]="_";
   }
   return $s;
 }
	
?>