/extremedating/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/extremedating/trunk

« back to all changes in this revision

Viewing changes to adduser.php

  • Committer: Gustav Hartvigsson
  • Date: 2013-04-15 22:24:25 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20130415222425-lez45gq9v06tqfid
* Opitimised add user code
* images are no longer stored as base64 encoded strings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
        <title>Extreme Dating - Create User</title>
24
24
        <link rel="stylesheet" type="text/css" href="css/main.css"/>
25
25
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
26
 
<head>
 
26
</head>
27
27
<?php
28
28
set_time_limit(0);
29
29
include "php/db.php";
39
39
  //If there is a $_POST that indicates that the add userscript should be run.
40
40
  $query = "";
41
41
  $output = "";
42
 
  if(isset($_FILES["image"]["tmp_name"])){
 
42
  if(isset($_FILES["image"]["tmp_name"]) && $_FILES['image']['size'] != 0 ){
43
43
    $tmpFile = $_FILES["image"]["tmp_name"];
44
44
    $handle = fopen($tmpFile,"r");
45
45
    $fileSize = $_FILES['image']['size'];
47
47
    $image = new Imagick();
48
48
    $image->readImageBlob($output);
49
49
    $image = stupid_convert_and_rescale($image, 280, 280, 'png');
50
 
    $output = base64_encode ($image);
 
50
    $output = $image;
51
51
  }
52
 
  if (isset($_SESSION['userType']) && $_POST['isSuperUser'] == true && $_SESSION['userType'] == 1) {
53
 
    $query = "INSERT INTO Users (
 
52
  $query = "INSERT INTO Users (
54
53
    loginName,
55
54
    shadow,
56
55
    firstName,
68
67
    '{$_POST['surName']}',
69
68
    '{$_POST['eMail']}',
70
69
    '{$_POST['city']}',
71
 
    '{$output}',
72
 
    '1'
 
70
    ? ,
 
71
    ?
73
72
    );";
 
73
  $q = null;
 
74
  try{
 
75
    $q = $db->prepare($query);
 
76
  } catch (PDOException $err) {
 
77
    echo "<pre>";
 
78
    var_dump($err);
 
79
    echo "</pre>";
 
80
    
 
81
  }
 
82
  if (isset($_SESSION['userType']) && $_POST['isSuperUser'] == true && $_SESSION['userType'] == 1) {
 
83
    $q->bindValue(2, '1');
74
84
  } else {
75
 
    $query = "INSERT INTO Users (
76
 
    loginName,
77
 
    shadow,
78
 
    firstName,
79
 
    surName,
80
 
    eMail,
81
 
    city,
82
 
    profileImage
83
 
    )
84
 
    
85
 
    VALUES(
86
 
    '{$_POST['name']}',
87
 
    '{$password}',
88
 
    '{$_POST['firstName']}',
89
 
    '{$_POST['surName']}',
90
 
    '{$_POST['eMail']}',
91
 
    '{$_POST['city']}',
92
 
    '{$output}'
93
 
    );";
 
85
    $q->bindValue(2, '0');
94
86
  }
95
87
  $success = NULL;
96
88
  try {
97
 
    $db->exec($query);
 
89
    $q->bindValue(1,$output, PDO::PARAM_LOB);
 
90
    $q->execute();
98
91
    $success = true;
99
92
  } catch (PDOException $err) {
100
93
    echo "<pre>";
101
94
    var_dump($err);
102
95
    var_dump($query);
 
96
    var_dump($q);
103
97
    echo "</pre>";
104
 
    $db->rollBack();
105
98
    $success = false;
106
99
  } if ($success) {
107
 
    echo "<body> <h1> New user added! </h1> </body>";
 
100
    /*echo "<pre>";
 
101
    var_dump($query);
 
102
    var_dump($q);
 
103
    echo "</pre>";
 
104
    */
 
105
    echo "<body> <h1> New user added! </h1>";
108
106
    sleep(1);
109
107
    header("Location:./index.php");
110
108
  }
164
162
            </tr>
165
163
          </table>
166
164
        </form>
167
 
      <?php
 
165
            </div>
 
166
    </div>
 
167
    <?php
168
168
}
169
 
      ?>
170
 
          </div>
171
 
    </div>
 
169
    ?>
 
170
 
172
171
  </body>
173
172
</html>