Index: trunk/globals.php =================================================================== diff -u -N -r4077 -r4120 --- trunk/globals.php (.../globals.php) (revision 4077) +++ trunk/globals.php (.../globals.php) (revision 4120) @@ -2062,5 +2062,51 @@ { return preg_match('/(a|A)/', GetTimeFormat() ); } + + /** + * Saves custom fields for old in-portal items + * + * @param string $prefix K4 prefix of item + * @param int $resource_id resource id of item + * @param int $item_type type of custom fields + */ + function saveCustomFields($prefix, $resource_id, $item_type) + { + $objCustomEdit = new clsCustomDataList(); + $CustomFields = new clsCustomFieldList($item_type); + + $data_changed = false; + for ($i = 0; $i < $CustomFields->NumItems(); $i++) { + $objField =& $CustomFields->GetItemRefByIndex($i); + $field_name = $objField->Get('FieldName'); + + $value = getCustomValue($field_name); + if ($value !== false) { + $objCustomEdit->SetFieldValue($objField->Get('CustomFieldId'), $resource_id, $value); + $data_changed = true; + } + } + + if ($data_changed) { + $objCustomEdit->SaveData($prefix, $resource_id); + } + } + + /** + * Returns custom field value from submit + * + * @param string $field_name + * @return mixed + */ + function getCustomValue($field_name) + { + if (IsAdmin()) { + $field_name = '_'.$field_name; + } + elseif (isset($_POST[strtolower($field_name)])) { + $field_name = strtolower($field_name); + } + return GetVar($field_name); + } ?> Index: trunk/kernel/frontaction.php =================================================================== diff -u -N -r4084 -r4120 --- trunk/kernel/frontaction.php (.../frontaction.php) (revision 4084) +++ trunk/kernel/frontaction.php (.../frontaction.php) (revision 4120) @@ -570,92 +570,71 @@ $u->DeleteFavorite(); DeleteModuleTagCache('kernel'); break; - case "m_acctinfo": -// phpinfo(INFO_VARIABLES); - $_POST=inp_escape($_POST); - $MissingCount = SetMissingDataErrors("m_acctinfo"); - $UserId = $_GET["UserId"]; - if($UserId != $objSession->Get("PortalUserId")) - { - $MissingCount++; - $FormError["m_acctinfo"]["UserId"] = language("lu_ferror_m_profile_userid"); - } - if(strlen($_POST["password"])>0) - { - if(($_POST["password"] != $_POST["passwordverify"]) || !strlen($_POST["passwordverify"])) - { - $MissingCount++; - $FormError["m_acctinfo"]["passwordverify"] = language("lu_ferror_pswd_mismatch"); - } + + case 'm_acctinfo': + $_POST = inp_escape($_POST); + $MissingCount = SetMissingDataErrors("m_acctinfo"); + $UserId = $_GET["UserId"]; + if ($UserId != $objSession->Get("PortalUserId")) { + $MissingCount++; + $FormError["m_acctinfo"]["UserId"] = language("lu_ferror_m_profile_userid"); + } + + if ($_POST["password"]) { + if (($_POST["password"] != $_POST["passwordverify"]) || !strlen($_POST["passwordverify"])) { + $MissingCount++; + $FormError["m_acctinfo"]["passwordverify"] = language("lu_ferror_pswd_mismatch"); + } + + if (strlen($_POST["password"])>30) { + // echo "VAR: ".$_POST["password"]; die(); + $MissingCount++; + $FormError["m_acctinfo"]["password"] = language("lu_ferror_pswd_toolong"); + } + + if (strlen($_POST['password']) < $objConfig->Get("Min_Password")) { + $MissingCount++; + $FormError["m_acctinfo"]["password"] = language("lu_ferror_pswd_tooshort"); + } + } - if(strlen($_POST["password"])>30) - { - // echo "VAR: ".$_POST["password"]; die(); - $MissingCount++; - $FormError["m_acctinfo"]["password"] = language("lu_ferror_pswd_toolong"); - } - - if (strlen($_POST['password']) < $objConfig->Get("Min_Password")) - { - $MissingCount++; - $FormError["m_acctinfo"]["password"] = language("lu_ferror_pswd_tooshort"); - } - } + $db =& GetADODBConnection(); + $email = GetVar('email'); + $test_id = $db->GetOne('SELECT PortalUserId FROM '.GetTablePrefix().'PortalUser WHERE Email = '.$db->qstr($email)); + if ($test_id && ($test_id != $objSession->Get('PortalUserId')) ) { + $MissingCount++; + $FormError["m_acctinfo"]["email"] = language("lu_ferror_email_duplicate"); + } - $db =& GetADODBConnection(); - $email = GetVar('email'); - $test_id = $db->GetOne('SELECT PortalUserId FROM '.GetTablePrefix().'PortalUser WHERE Email = '.$db->qstr($email)); - if($test_id && ($test_id != $objSession->Get('PortalUserId')) ) - { - $MissingCount++; - $FormError["m_acctinfo"]["email"] = language("lu_ferror_email_duplicate"); - } - - if(!$MissingCount) - { - /* save profile */ - $u =& $objUsers->GetItem($UserId); - $status = $u->Get("Status"); - $dob = adodb_mktime(0, 0, 0, $_POST['dob_month'], $_POST['dob_day'], $_POST['dob_year']); - $password = strlen($_POST["password"]) > 0 ? md5($_POST["password"]) : ''; - - $fields_hash = Array( 'Login' => $_POST['username'], - 'FirstName' => $_POST['firstname'], - 'LastName' => $_POST['lastname'], - 'Company' => $_POST['company'], - 'Email' => $_POST['email'], - 'Status' => $status, - 'Phone' => $_POST['phone'], - 'Fax' => $_POST['fax'], - 'Street' => $_POST['street'], - 'Street2' => $_POST['street2'], - 'City' => $_POST['city'], - 'State' => $_POST['state'], - 'Zip' => $_POST['zip'], - 'Country' => $_POST['country'], - 'dob' => $dob, - 'MinPwResetDelay' => $_POST['minpwresetdelay'], - - ); - - $user =& $objUsers->Edit_User_NEW($UserId, $fields_hash); + if (!$MissingCount) { + /* save profile */ + $u =& $objUsers->GetItem($UserId); + $status = $u->Get("Status"); + $dob = adodb_mktime(0, 0, 0, $_POST['dob_month'], $_POST['dob_day'], $_POST['dob_year']); + $password = strlen($_POST["password"]) > 0 ? md5($_POST["password"]) : ''; - $ResourceId= $u->Get("ResourceId"); - $objCustomDataList->LoadResource($ResourceId); - $objCustomFields = new clsCustomFieldList(6); - for($i=0;$i<$objCustomFields->NumItems(); $i++) - { - $field = & $objCustomFields->GetItemRefByIndex($i); - $fieldid= $field->Get("CustomFieldId"); - $fname = $field->Get("FieldName"); - if(isset($_POST[$fname])) - $objCustomDataList->SetFieldValue($fieldid,$ResourceId,$_POST[$fname]); - elseif(isset($_POST[strtolower($fname)])) - $objCustomDataList->SetFieldValue($fieldid,$ResourceId,$_POST[strtolower($fname)]); - } - $objCustomDataList->SaveData('u', $ResourceId); - + $fields_hash = Array( 'Login' => $_POST['username'], + 'FirstName' => $_POST['firstname'], + 'LastName' => $_POST['lastname'], + 'Company' => $_POST['company'], + 'Email' => $_POST['email'], + 'Status' => $status, + 'Phone' => $_POST['phone'], + 'Fax' => $_POST['fax'], + 'Street' => $_POST['street'], + 'Street2' => $_POST['street2'], + 'City' => $_POST['city'], + 'State' => $_POST['state'], + 'Zip' => $_POST['zip'], + 'Country' => $_POST['country'], + 'dob' => $dob, + 'MinPwResetDelay' => $_POST['minpwresetdelay'], + + ); + + $user =& $objUsers->Edit_User_NEW($UserId, $fields_hash); + saveCustomFields('u', $u->Get('ResourceId'), 6); } DeleteModuleTagCache('kernel'); break; @@ -774,28 +753,9 @@ $metadesc = $_POST["meta_description"]; $keywords = $_POST["meta_keywords"]; $parent = $objCatList->CurrentCategoryID(); - $cat =& $objCatList->Add($parent, $name, $desc, $CreatedOn, - 0, $perm, 2, 2, 2, 0, $keywords,$metadesc); + $cat =& $objCatList->Add($parent, $name, $desc, $CreatedOn, 0, $perm, 2, 2, 2, 0, $keywords,$metadesc); + saveCustomFields('c', $cat->Get('ResourceId'), $cat->type); - $CatResourceId= $cat->Get('ResourceId'); - $objCustomFields = new clsCustomFieldList($cat->type); - $field_list = $objCustomFields->Query_CustomField('Type='.$cat->type); - for($i=0;$i<$objCustomFields->NumItems(); $i++) - { - $field = & $objCustomFields->GetItemRefByIndex($i); - $fieldid= $field->Get('CustomFieldId'); - $fname = $field->Get('FieldName'); - if(isset($_POST[$fname])) - { - $objCustomDataList->SetFieldValue($fieldid,$CatResourceId,$_POST[$fname]); - } - elseif(isset($_POST[strtolower($fname)])) - { - $objCustomDataList->SetFieldValue($fieldid,$CatResourceId,$_POST[strtolower($fname)]); - } - } - $objCustomDataList->SaveData('c', $CatResourceId); - $cat->UpdateCachedPath(); $cat->Update(); $cat->UpdateACL(); Index: trunk/kernel/include/category.php =================================================================== diff -u -N -r4077 -r4120 --- trunk/kernel/include/category.php (.../category.php) (revision 4077) +++ trunk/kernel/include/category.php (.../category.php) (revision 4120) @@ -2066,6 +2066,40 @@ return $nav; } + + function &Add_NEW($fields_hash) + { + global $objSession; + + $fields_hash['CreatedById'] = $objSession->Get('UserId'); + + $d = new clsCategory(NULL); + $fields_hash['Filename'] = $d->StripDisallowed($fields_hash['Filename']); + $d->tablename = $this->SourceTable; + + if ( $d->UsingTempTable() ) { + $d->Set('CategoryId', -1); + } + $d->idfield = 'CategoryId'; + + foreach ($fields_hash as $field_name => $field_value) { + $d->Set($field_name, $field_value); + } + + $d->Create(); + if ($d->Get('Status') == STATUS_ACTIVE) { + $d->SendUserEventMail("CATEGORY.ADD", $objSession->Get("PortalUserId")); + $d->SendAdminEventMail("CATEGORY.ADD"); + } + else + { + $d->SendUserEventMail("CATEGORY.ADD.PENDING", $objSession->Get("PortalUserId")); + $d->SendAdminEventMail("CATEGORY.ADD.PENDING"); + } + $d->UpdateCachedPath(); + return $d; + } + function &Add( $ParentId, $Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, $New, $Pop, $Priority, $MetaKeywords,$MetaDesc, $auto_filename = 1, $filename = '') {