Advertisement
jonwitts

iSAMS Student Photos for Moodle

Feb 10th, 2015
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2.  
  3. ///////////////////////////////
  4. // This script will query your iSAMS database and return the location
  5. // and network username of the latest photos for all students
  6. // with a school photo on the system
  7. //////////////////////////////
  8.  
  9. /////////////////////////////
  10. // Uncomment for debugging
  11. /////////////////////////////
  12.  
  13. //error_reporting(E_ALL);
  14. //ini_set("display_errors", 1);
  15.  
  16. ////////////////////////////
  17. // Set your iSAMS database connection details here
  18. ///////////////////////////
  19.  
  20. $host="FQDN of your MSSQL Server";
  21. $dbname="iSAMS DB Name";
  22. $dbuser="iSAMS DB User";
  23. $dbuserpass="Really strong password!";
  24.  
  25. try
  26. {
  27.   $db = new PDO("dblib:host=$host;dbname=$dbname", $dbuser, $dbuserpass);
  28. }
  29. catch(PDOException $e)
  30. {
  31.   echo "Connection failed: " . $e->getMessage();
  32. }
  33.  
  34. echo "Connected to the database\n";
  35.  
  36.  
  37. $query = "SELECT txtEmailAddress, (SELECT TOP (1) txtPath FROM TblPupilManagementPictures WHERE (txtSchoolID = TblPupilManagementPupils.txtSchoolID) ORDER BY intOrder DESC) AS txtPupilPicturePath FROM TblPupilManagementPupils WHERE (intSystemStatus = '1') AND ((SELECT TOP (1) txtPath FROM TblPupilManagementPictures AS TblPupilManagementPictures_1 WHERE (txtSchoolID = TblPupilManagementPupils.txtSchoolID) ORDER BY intOrder DESC) IS NOT NULL)";
  38. $statement = $db->prepare($query);
  39. $statement->execute();
  40.  
  41. echo "Executing query\n";
  42.  
  43. $data = fopen('user-picture-locations.csv', 'w');
  44.  
  45. while ($row = $statement->fetchAll(PDO::FETCH_NUM))
  46. {
  47.     foreach ($row as $rowitem)
  48.     {
  49.         $email = $rowitem[0];
  50.         $split = preg_split("[@]", $email);
  51.         $username = $split[0];
  52.  
  53.         $filelocation = $rowitem[1];
  54.         $split = preg_split("[/]", $filelocation);
  55.         $year = $split[3];
  56.         $date = $split[4];
  57.         $file = $split[5];
  58.  
  59.         $bashline = "cd iSAMS\; cd iSAMS.Files\; cd studentimages\; cd " . $year . "\; cd " . $date . "\; prompt; get " . $file . "," . $file . "," . $username . ".jpg," . PHP_EOL;
  60.         echo "Writing " . $username . " line to file\n";
  61.         fwrite($data, $bashline);
  62.     }
  63. }
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement