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
|
function SaveProfile( $option, $Itemid )
{
global $database, $my, $mosConfig_absolute_path;
// Management for uploaded image.
if ( function_exists("imagecreatefromjpeg") && isset($_FILES) && preg_match("/[^\.]+\.(png|jpg|jpeg|PNG|JPG|JPEG)$/",$_FILES['imgfile']['name']) ) {
//echo 'TEST<br />';
if ( is_uploaded_file($_FILES['imgfile']['tmp_name']) ) {
//echo "Fichier valide<br />";
$uploaddir = $mosConfig_absolute_path."/images/stories/"._PBK_PARAM_IMGDIR;
$uploadfile = $uploaddir.$my->id; //.".jpg";
$array_img = getimagesize($_FILES['imgfile']['tmp_name']);
if ($array_img !== false) {
$width_orig = $array_img[0];
$height_orig = $array_img[1];
$type_orig = $array_img['mime'];
switch ($type_orig) {
//case "image/gif" :
//$uploadfile .= ".gif";
//$type = "gif";
//echo "TESTGIF<br />";
//break;
case "image/jpeg" :
$uploadfile .= ".jpg";
$type = "jpeg";
break;
case "image/png" :
$uploadfile .= ".png";
$type = "png";
break;
default :
$uploadfile .= ".jpg";
$type = "jpeg";
}
exec('rm '.$uploaddir.'/'.$my->id.'.*');
$func_create = "imagecreatefrom".$type;
$img_src = $func_create($_FILES['imgfile']['tmp_name']);
$height_dst = 150;
$width_dst = 150;
if ($height_orig > $height_dst || $width_orig > $width_dst ) {
if ($width_dst && ($width_orig < $height_orig)) {
$width_dst = ($height_dst / $height_orig) * $width_orig;
}
else {
$height_dst = ($width_dst / $width_orig) * $height_orig;
}
$img_dst = imagecreatetruecolor($width_dst, $height_dst);
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $width_dst, $height_dst, $width_orig, $height_orig);
$func_save = "image".$type;
$func_save($img_dst, $uploadfile);
//echo "Fichier redimensionné et copié<br />";
}
else {
$func_save = "image".$type;
$func_save($img_src, $uploadfile);
//echo "Fichier copié tel quel<br />";
}
$_POST['picture'] = basename($uploadfile);
}
}
}
// We uppercase the first letter of name and position to avoid ordering problems in staff list.
$_POST['name'] = ucfirst( $_POST['name'] );
$_POST['position'] = ucfirst( $_POST['position'] );
$row = new mospeoplebook( $database );
// bind --> cf line 612 in file includes/database.php
if (!$row->bind( $_POST )) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
exit();
}
// Don't need the following lines cause $my is global.
//$mainframe = new mosMainFrame( $database, $option, '.' );
//$mainframe->initSession();
//$my = $mainframe->getUser();
$row->id = $my->id;
// Test if this user id is already used in peoplebook table.
$database->setQuery("SELECT id FROM #__peoplebook WHERE id = '$row->id'");
// If not, we add the new entry in peoplebook table.
if ( !$database->loadResult() ) {
// We automagically publish the new entry if publication policy allow that.
$row->published = _PBK_PARAM_AUTOPUBLI;
$database->insertObject('#__peoplebook',$row,'id');
}
else {
#$row->date = date( "Y-m-d H:i:s" );
// store --> cf line 656 in file includes/database.php
if (!$row->store()) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
exit();
}
}
$row->updateOrder( "catid='$row->catid'" );
$data = $_POST[data];
$idset_2 = $_POST[cfdIDs];
$i = 0;
foreach( $_POST[cfIDs] as $cfID )
{
$dataset[data] = $data[$cfID];
$dataset[cfID] = $cfID;
$dataset[cfdID] = $idset_2[$i];
$dataset[uID] = $row->id;
$row2 = new mospeoplebook_customfields_data( $database );
if ( !$row2->bind( $dataset ) )
{
echo "<script> alert('".$row2->getError()."'); window.history.go(-1); </script>\n";
exit();
}
if ( !$row2->store( $dataset[cfdID] ) )
{
echo "<script> alert('".$row2->getError()."'); window.history.go(-1); </script>\n";
exit();
}
$row2->updateOrder( "cfdID='$row2->cfdID'" );
$i++;
}
mosRedirect( "index.php?option=$option&Itemid=47".$Itemid_redirect );
} |
Partager