/**
  * Create a new company
  *
  * @param company array. An array containing the company information,
  * example:
  * \code
  * array(
  *    'name'     => 'ACME',
  *    'address1' => '1110 Gateway Drive',
  *    'address2' => '',
  *    'address3' => '',
  *    'zip_code' => 'CA 94404',
  *    'city'     => 'San Mateo',
  *    'country'  => 'US', // ISO 3166-1 alpha-2 country code
  *    'email'    => '*****@*****.**',
  * )
  * \endcode
  *
  * @return company_id int. The ID of the newly created company.
  *
  */
 static function Create(array $company = array())
 {
     CybPHP_Validate::ValidateCompanyName($company['name']);
     CybPHP_Validate::ValidateAddress($company['address1']);
     CybPHP_Validate::ValidateZipCode($company['zip_code']);
     CybPHP_Validate::ValidateCity($company['city']);
     CybPHP_Validate::ValidateCountry($company['country']);
     CybPHP_Validate::ValidateEmail($company['email']);
     WebfinanceUser::ValidateExists($company['email']);
     WebfinanceCompany::ValidateAvailable($company['name']);
     if (empty($company['address2'])) {
         $company['address2'] = '';
     } else {
         CybPHP_Validate::ValidateAddress($company['address2']);
     }
     if (empty($company['address3'])) {
         $company['address3'] = '';
     } else {
         CybPHP_Validate::ValidateAddress($company['address3']);
     }
     foreach (array('name', 'address1', 'address2', 'address3', 'zip_code', 'city', 'country', 'email') as $value) {
         $company[$value] = mysql_escape_string($company[$value]);
     }
     $user_id = WebfinanceUser::GetIdFromEmail($company['email']);
     CybPHP_MySQL::Query('BEGIN');
     CybPHP_MySQL::Query('INSERT INTO webfinance_clients SET ' . "nom          = '{$company['name']}', " . 'date_created = NOW(), ' . "addr1        = '{$company['address1']}', " . "addr2        = '{$company['address2']}', " . "addr3        = '{$company['address3']}', " . "cp           = '{$company['zip_code']}', " . "ville        = '{$company['city']}', " . "pays         = '{$company['country']}', " . "email        = '{$company['email']}'");
     $company_id = mysql_insert_id();
     CybPHP_MySQL::Query('INSERT INTO webfinance_clients2users SET ' . "id_client = {$company_id}, " . "id_user   = {$user_id}");
     CybPHP_MySQL::Query('COMMIT');
     return $company_id;
 }
示例#2
0
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
//
require_once '../htdocs/inc/sso.php';
require_once '../htdocs/inc/smarty.php';
try {
    // Create user if he/she does not exist yet
    try {
        WebfinanceUser::ValidateExists($_SESSION['cybsso_user']['email']);
    } catch (Exception $e) {
        WebfinanceUser::Create($_SESSION['cybsso_user']['email']);
    }
    $user = new WebfinanceUser($_SESSION['cybsso_user']['email']);
    // Ask the user to create a company if he/she doesn't own one
    if (count($user->GetCompanies()) == 0) {
        header('Location: /company/new');
        exit;
    }
    /*
    si return_url est définie, alors on redirige (dans le cas de la creation d'un
    compte)
    redirect $return_url
    */
    /*
 function testValidateExistsOK()
 {
     $email = '*****@*****.**';
     WebfinanceUser::Create($email);
     WebfinanceUser::ValidateExists($email);
 }