Dwie propozycje, pierwsza dodaje dane "z zewnątrz" do Epesi, druga to próba rejestracji, ale coś nie bangla. Pozostawiłem trochę komentarzy, może się przysłużą.
Uwaga na dodawanie usera przez RecordBrowser, jedno "złe pole" i nowego superadmina ciężko wyp... wyprosić z bazy albo zdjąć mu uprawnienia ;] Pozostaje baza
<?php
/**
* Index file
*
* This file includes all 'include files', loads modules
* and gets output of default module.
* @author Paul Bukowski <pbukowski@telaxus.com>
* @copyright Copyright © 2006, Telaxus LLC
* @license MIT
* @version 1.0
* @package epesi-base
*/
#$$hour = intval();
/* plik ma sie znalezc w katalogu EPESI_ROOT_DIR
*
* Jesli bedzie gdzie indziej nalezy ustawic sciezki do folderow, z ktorych
* include'uje pliki
*
* */
/* $h = intval(date('H'));
if ($h >= 20) {
die('Po 19 wieczorynka i lulu a nie EPESI :)');
}
*/
if(version_compare(phpversion(), '5.4.0')==-1)
die("You are running an old version of PHP, php 5.4 required.");
if(trim(ini_get("safe_mode")))
die('You cannot use EPESI with PHP safe mode turned on - please disable it. Please notice this feature is deprecated since PHP 5.3 and will be removed in PHP 6.0.');
define('_VALID_ACCESS',1);
require_once('include/data_dir.php');
if(!file_exists(DATA_DIR.'/config.php')) {
header('Location: setup.php');
exit();
}
if(!is_writable(DATA_DIR))
die('Cannot write into "'.DATA_DIR.'" directory. Please fix privileges.');
// require_once('include/include_path.php');
require_once('include/config.php');
require_once('include/maintenance_mode.php');
require_once('include/error.php');
require_once('include/misc.php');
require_once('include/database.php');
require_once('include/variables.php');
define('CID',false); /* gdy true, sesja sie wywala dla niezalogowanego user'a */
//define('READ_ONLY_SESSION', 1);
require_once('include.php');
ModuleManager::load_modules();
function display_vars($vars) {
foreach ($vars as $key => $value) {
echo "$key => $value</br>";
}
}
/*
function params_to_commondata($params) {
Utils_CommonDataCommon::extend_array("/out_of_epesi/".date('Y-m-d_H_i_s'), $params);
}
*/
function quickform_add_contact() {
include 'bootstrap_my.html';
echo "<h3><font color='0FAAF0'>Uwaga: Formularz nie bedzie sprawdzal poprawnosci danych.</font></h3></br>";
$form = new HTML_QuickForm('qform', 'post', 'data2epesi.php');
$form->addElement('header', null, _M('Wypelnij formularz'));
$must_have = [
'id', 'created_by', 'created_on', ':active', 'last_name', 'first_name', 'company_name', 'related_companies',
'group', 'title', 'work_phone', 'mobile_phone', 'fax', 'email', 'web_address', 'address_1', 'address_2', 'city',
'country', 'zone', 'county', 'postal_code', 'permission', 'japierdole', 'subcounty', 'home_phone', 'home_address_1',
'home_address_2', 'home_city', 'birth_date', 'home_country', 'home_zone', 'home_county', 'home_postal_code',
'login', 'username', 'set_password', 'confirm_password', 'admin', 'access'
];
$should_not_display = [
'id', 'created_on', 'created_by', 'related_companies', 'group', 'permission', 'admin', 'access', '_active', ':active',
'login', 'username', 'set_password', 'confirm_password', 'company_name', 'country', 'japierdole'
];
for($i=0; $i<count($must_have); $i++) {
$key = $must_have[$i];
$to_continue = false;
foreach ($should_not_display as $cannot_key)
if ($key == $cannot_key)
$to_continue = true;
if ($to_continue)
continue;
$form->addElement('text', $must_have[$i], _M($must_have[$i]), ['value'=>"x"]);
}
$form->addElement('submit', 'submit', _M('Wyslij'));
if ($form->isSubmitted()) {
$values = $form->exportValues();
//display_vars($values);
//Acl::set_user(Base_UserCommon::get_user_id('Administrator'), true); //udajemy zalogowanie
Acl::set_sa_user();
$rs = new RBO_RecordsetAccessor('contact');
$count = $rs->get_records_count();
$my_contact = Utils_RecordBrowserCommon::get_record('contact', 1);
foreach($values as $k=>$v) {
//echo "<h4>$k => $v</h4>";
$my_contact[$k] = $v;
}
$my_contact['f_company_name'] = 0;
unset($my_contact['birth_date']);
$my_contact['id'] = $count;
$my_contact['created_by'] = 1;
$my_contact['created_on'] = date("Y-m-d H:i:s")."";
$my_contact['related_companies'] = [];
$my_contact['group'] = []; //['office' => 'office', 'field' => 'field'];
$my_contact['permission'] = '0';
$my_contact['login'] = '0';
$my_contact[':active'] = '0';
$my_contact['permission'] = '0';
$my_contact['admin'] = false; /* nie jest adminem */
$my_contact['_active'] = '0'; /* konto nie jest aktywne */
$id = Utils_RecordBrowserCommon::new_record('contact', $my_contact);
echo "ID=$id</br>";
var_dump(Utils_RecordBrowserCommon::get_record('contact', $id));
Acl::set_user(Base_UserCommon::get_user_id('Administrator'), false); //logout
}
$form->display();
}
quickform_add_contact();
//var_dump(CRM_ContactsCommon::get_my_record());
/*
switch($_SERVER['REQUEST_METHOD']) {
case 'GET': quickform_add_contact(); break;
case 'POST':
// echo "Dziekujemy";
}
Propozycja rejestracji nowego user'a, próbowałem na dwa sposoby - poprzez dodanie na bezczela, ale później miałem komplikacje, albo przez new contact, ale nie zawsze mi działał. Dokończę kiedyś, niemniej może się komuś przydać ?
<?php
ob_start();
define('CID',false);
define('SET_SESSION',false);
define('PER_PAGE',50);
require_once('include.php');
ModuleManager::load_modules();
?>
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
</head>
<body>
<?php
include 'bootstrap_my.html';
/*
* @param $msg string or array of string
* */
function show_error($msg) {
if (!is_array($msg))
$msg = [$msg];
echo "<center><font color='red'><b><h3>";
foreach ($msg as $m) {
echo "$m</br>";
}
echo "</h3></b></font></center>";
return -1;
}
function form_validated_register_new_user($values) {
Acl::set_user(Base_UserCommon::get_user_id('Administrator'), true);
//var_dump($values);
/*Utils_RecordBrowserCommon::new_record('contact',array('last_name'=>$vals['last'],'first_name'=>$vals['first'],'country'=>'PL','mobile_phone'=>$vals['phone'],'email'=>$vals['mail'],'login'=>'new','username'=>...,'set_password'=>...));*/
Acl::set_user(0);
$rs = new RBO_RecordsetAccessor('contact');
$count = $rs->get_records_count();
$contact = Utils_RecordBrowserCommon::get_record('contact', 1);
var_dump($contact);
//return;
foreach ($contact as $k=>$v) /*reset wartosci */
$contact[$k] = '';
foreach ($values as $k=>$v) /*qform -> kontakt*/
$contact[$k] = $v;
//DB::Execute('INSERT INTO user_login(login) VALUES(%s)', )
//DB::Execute('UPDATE user_login SET active=%b WHERE id=%d',array(false, Base_UserCommon::get_user_id($values['login'])));
//Base_User_LoginCommon::add_user($values['login'], $values['email'], $values['set_password']);
//$user_id = Base_UserCommon::get_user_id($values['login']);
/*@var_dump($values);
@var_dump($user_id);
@var_dump($rec_id);
@var_dump($contact);*/
$contact['f_company_name'] = 0;
unset($contact['birth_date']);
$contact['id'] = $count;
$contact['created_by'] = 1;
$contact['created_on'] = date("Y-m-d H:i:s")."";
$contact['related_companies'] = [];
$contact['group'] = ['office' => 'office', 'field' => 'field'];
$contact['f_permission'] = 1;
$contact['f_email'] = 1;
$contact['email'] = 0;
$contact['admin'] = false; /* nie jest adminem */
$contact['_active'] = 1; /* konto nie jest aktywne */
//Base_User_LoginCommon::add_user($values['login'], $values['mail']);
$id = Utils_RecordBrowserCommon::new_record('contact', $contact);
var_dump($id);
var_dump(Utils_RecordBrowserCommon::get_record('contact', $id));
//$rec_id = Utils_RecordBrowserCommon::new_record('contact', $values);
//Base_UserCommon::add_user();// ??
/* Make sure new user is not admin or `o zgrozo` superadmin! * /
DB::Execute('UPDATE user_login SET admin=%d WHERE id=%d',array(1, $user_id));
*/
Acl::set_user(Base_UserCommon::get_user_id('Administrator'), false);
}
function render_register_form() {
$form = new HTML_QuickForm('XXX', 'post','?'.http_build_query($_GET));
$form->addElement('header', null, _M('Rejestracja'));
$form->addElement('text','first_name',_M('Imię'), ['value'=>'xxxxxxxxxx']);
$form->addElement('text','last_name',_M('Nazwisko'), ['value'=>'xxxxxxxxxx']);
$form->addElement('text','email',_M('E-mail'), ['value'=>'xxxx@xxxx.pl']);
$form->addElement('text','phone',_M('Telefon'), ['value'=>'888888888']);
$form->addElement('header', null, _M('Nowy uzytkownik'));
$form->addElement('text', 'login', _M('Login'), ['value'=>'xxxxxxxxxx']);
$form->addElement('password', 'set_password', _M('Haslo'), ['value'=>'xxxxxxxxxx']);
$form->addElement('password', 'confirm', _M('Powtorz haslo'), ['value'=>'xxxxxxxxxx']);
foreach (['first_name', 'last_name', 'email', 'phone'] as $k) {
$form->addRule($k, 'Pole wymagane', 'required');
}
$form->addRule('login','Pole wymagane','required');
$form->addRule('set_password','Pole wymagane','required');
$form->addRule('confirm','Pole wymagane','required');
$form->addElement('submit', null, _M('Wyslij'));
if($form->validate()) {
$values = $form->exportValues();
$errors = [];
/* if (strlen($values['login'])<6) {
$errors[] = 'Login za krotki';
}
if (!Base_User_LoginCommon::check_username_free($values['login'])) {
$errors[] = 'Login zajety';
}
if ($values['set_password'] != $values['confirm']) {
$errors[] = 'Podane hasla roznia sie';
}
if (strlen($values['set_password']) < 8) {
$errors[] = 'Haslo jest za krotkie';
} */
/* if (DB::GetOne("select mail from user_password where mail='".$values['email']."'") != null) {
$errors[] = "Adres e-mail zajety";
} */
if (count($errors)>0) {
show_error($errors);
}
else {
//unset($values['confirm']);
form_validated_register_new_user($values);
}
}
$form->display();
}
function test() {
echo DB::Execute('select * from user_login')."";
//var_dump();
/* $mail = 'aleksander.starostka@gmail.com';
if (DB::GetOne("select mail from user_password where mail='$mail'") != null) {
echo "User zajety";
}
else {
echo "FREE KURWA";
} */
/* Acl::set_sa_user();
$me = Utils_RecordBrowserCommon::get_record('contact', 1);
$keys = array_keys($me);
foreach ($keys as $k) {
echo "\$me['$k'] = ''</br>";
}*/
}
/*
switch($_SERVER['REQUEST_METHOD']) {
case 'GET': test(); break;
case 'POST': thx(); break;
}*/
//test();
render_register_form();
?>
</body>
</html>
<?php
$content = ob_get_contents();
ob_end_clean();
require_once('libs/minify/HTTP/Encoder.php');
$he = new HTTP_Encoder(array('content' => $content));
if (MINIFY_ENCODE) $he->encode();
$he->sendAll();
exit();