| 1 | package DHTMLX::Core; | ||
| 2 | |||
| 3 | =encoding utf8 | ||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | DHTMLX::Core - Basics tasks on DHTMLX Perl module. | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | use DHTMLX::Core; | ||
| 11 | |||
| 12 | # Instantiating DHTMLX::Core object | ||
| 13 | |||
| 14 | # using ASP - more about $Request, $Response and $Server on http://www.apache-asp.com/objects.html | ||
| 15 | my $core = DHTMLX::Core->new( "ASP", $Request, $Response, $Server ); | ||
| 16 | |||
| 17 | # using CGI | ||
| 18 | my $core = DHTMLX::Core->new( "CGI" ); | ||
| 19 | |||
| 20 | # usando Catalyst | ||
| 21 | my $core = DHTMLX::Core->new( "Catalyst" ); | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | DHTMLX::Core provides generic features used on entire DHTMLX Perl module | ||
| 26 | |||
| 27 | =cut | ||
| 28 | |||
| 29 | # ABSTRACT: Basics tasks on DHTMLX Perl module | ||
| 30 | |||
| 31 | use strict; | ||
| 32 | use warnings 'all'; | ||
| 33 | use DBI; | ||
| 34 | use JSON; | ||
| 35 | use HTML::Entities; | ||
| 36 | |||
| 37 | use POSIX qw(locale_h strtod setlocale LC_MONETARY LC_CTYPE); | ||
| 38 | |||
| 39 | # configuracoes de localidade | ||
| 40 | setlocale(LC_CTYPE, "pt_BR"); | ||
| 41 | setlocale(LC_MONETARY, "pt_BR"); | ||
| 42 | |||
| 43 | use vars qw ( | ||
| 44 | $VERSION | ||
| 45 | ); | ||
| 46 | |||
| 47 | =head1 VERSION | ||
| 48 | |||
| 49 | 0.004 | ||
| 50 | |||
| 51 | =cut | ||
| 52 | $VERSION = '0.004'; | ||
| 53 | |||
| 54 | # variaveis e definicoes iniciais | ||
| 55 | my $dsn; | ||
| 56 | my $conexao; | ||
| 57 | my $SGDB = "PostgreSQL"; # PostgreSQL # SQL Server | ||
| 58 | my $hostbanco = "localhost"; # 127.0.0.1 | ||
| 59 | my $instancia = "CLOUDWORK\\SQLEXPRESS"; # \\ duas barras para scape CLOUDWORK\\SQLEXPRESS - Para MS SQL Version | ||
| 60 | my $nomebanco = "database"; | ||
| 61 | my $userbanco = "user"; # sa | ||
| 62 | my $senhabanco = 'password'; | ||
| 63 | my $driver = "ADO"; # Pg # ADO # ODBC | ||
| 64 | |||
| 65 | my $framework = "ASP"; | ||
| 66 | my $request; | ||
| 67 | my $response; | ||
| 68 | my $server; | ||
| 69 | my $cgi; | ||
| 70 | |||
| 71 | |||
| 72 | # construtor new do objeto | ||
| 73 | sub new | ||
| 74 | { | ||
| 75 | my $class = shift; | ||
| 76 | my $self = { | ||
| 77 | framework => shift || undef, | ||
| 78 | request => shift || undef, | ||
| 79 | response => shift || undef, | ||
| 80 | server => shift || undef, | ||
| 81 | }; | ||
| 82 | |||
| 83 | if(defined($self->{framework})) | ||
| 84 | { | ||
| 85 | $framework = $self->{framework}; | ||
| 86 | } | ||
| 87 | if($framework eq "ASP") | ||
| 88 | { | ||
| 89 | # importa objetos ASP | ||
| 90 | $request = $self->{request}; | ||
| 91 | $response = $self->{response}; | ||
| 92 | $server = $self->{server}; | ||
| 93 | } | ||
| 94 | elsif($framework eq "CGI") | ||
| 95 | { | ||
| 96 | use CGI; | ||
| 97 | $cgi = new CGI; | ||
| 98 | } | ||
| 99 | |||
| 100 | |||
| 101 | bless $self, $class; | ||
| 102 | return $self, $class; | ||
| 103 | } | ||
| 104 | |||
| 105 | =head1 METHODS | ||
| 106 | |||
| 107 | |||
| 108 | =head2 conectar | ||
| 109 | |||
| 110 | my $conexao = $core->conectar(); | ||
| 111 | |||
| 112 | Provides a active DBI connection | ||
| 113 | |||
| 114 | $conexao->disconnect; | ||
| 115 | |||
| 116 | End the active connection | ||
| 117 | |||
| 118 | =cut | ||
| 119 | sub conectar() | ||
| 120 | { | ||
| 121 | if($driver eq "ADO") | ||
| 122 | { | ||
| 123 | if($SGDB eq "PostgreSQL") | ||
| 124 | { | ||
| 125 | $dsn=" DRIVER={PostGreSQL UNICODE}; | ||
| 126 | SERVER=$hostbanco; | ||
| 127 | DATABASE=$nomebanco; | ||
| 128 | UID=$userbanco; | ||
| 129 | PWD=$senhabanco; | ||
| 130 | OPTION=3; | ||
| 131 | set lc_monetary=pt_BR; | ||
| 132 | set lc_numeric=pt_BR; | ||
| 133 | set lc_time=pt_BR; | ||
| 134 | SET datestyle TO POSTGRES, DMY; | ||
| 135 | "; | ||
| 136 | |||
| 137 | $conexao = DBI->connect("DBI:$driver:$dsn") or die "problema ao conectar ao $SGDB"; | ||
| 138 | } | ||
| 139 | elsif($SGDB eq "SQL Server") | ||
| 140 | { | ||
| 141 | $dsn = ' | ||
| 142 | Provider = SQLOLEDB.1; | ||
| 143 | Password = '.$senhabanco.'; | ||
| 144 | Persist Security Info = True; | ||
| 145 | User ID = '.$userbanco.'; | ||
| 146 | Initial Catalog = '.$nomebanco.'; | ||
| 147 | Data Source = '.$instancia.'; | ||
| 148 | SET DATEFORMAT dmy; | ||
| 149 | '; | ||
| 150 | #=> | ||
| 151 | #===> SQL Server Native Client 10.0 dando erro com ORDER BY | ||
| 152 | #=> | ||
| 153 | #DRIVER = {SQL Server Native Client 10.0}; | ||
| 154 | #SERVER = '.$instancia.'; | ||
| 155 | #DATABASE = '.$nomebanco.'; | ||
| 156 | #UID = '.$userbanco.'; | ||
| 157 | #PWD = '.$senhabanco.'; | ||
| 158 | $conexao = DBI->connect('DBI:'.$driver.':'.$dsn.'') or die "problema ao conectar ao $SGDB"; | ||
| 159 | } | ||
| 160 | } | ||
| 161 | elsif($driver eq "Pg") | ||
| 162 | { | ||
| 163 | $dsn = "dbname = $nomebanco; | ||
| 164 | host = $hostbanco; | ||
| 165 | "; | ||
| 166 | $conexao = DBI->connect("DBI:$driver:$dsn", "$nomebanco", "$senhabanco", {'RaiseError' => 1}) or die "problema ao conectar ao $SGDB"; | ||
| 167 | } | ||
| 168 | elsif($driver eq "ODBC") | ||
| 169 | { | ||
| 170 | $conexao = DBI->connect('dbi:ODBC:advmanagerSQL', 'sa', 'Qw3@lklk2244') or die "problema ao conectar ao $SGDB"; | ||
| 171 | } | ||
| 172 | return $conexao; | ||
| 173 | } | ||
| 174 | |||
| 175 | =head2 SGDB | ||
| 176 | |||
| 177 | my $sgdb_version = $core->SGDB(); | ||
| 178 | |||
| 179 | Return the active sgdb factory | ||
| 180 | |||
| 181 | |||
| 182 | =cut | ||
| 183 | sub SGDB() | ||
| 184 | { | ||
| 185 | my($self) = @_; | ||
| 186 | return $SGDB; | ||
| 187 | } | ||
| 188 | |||
| 189 | =head2 noInjection | ||
| 190 | |||
| 191 | print $core->noInjection("te'st"); | ||
| 192 | # prints te'st | ||
| 193 | |||
| 194 | Escape ' character with a html entitie. | ||
| 195 | It is used in Get and Post methods of this module | ||
| 196 | Prevent sql injection | ||
| 197 | |||
| 198 | |||
| 199 | =cut | ||
| 200 | sub noInjection | ||
| 201 | { | ||
| 202 | my($self, $string) = @_; | ||
| 203 | $string =~ s/\'/\&apos\;/g; | ||
| 204 | return $string; | ||
| 205 | } | ||
| 206 | |||
| 207 | =head2 error | ||
| 208 | |||
| 209 | undef($foo); | ||
| 210 | $foo = $foo || $core->error( "foo is undefined" ) | ||
| 211 | |||
| 212 | # prints | ||
| 213 | |||
| 214 | { | ||
| 215 | "response":"foo is undefined", | ||
| 216 | "status":"error" | ||
| 217 | } | ||
| 218 | |||
| 219 | Prints a JSON string with errors details and exit the application; | ||
| 220 | |||
| 221 | |||
| 222 | =cut | ||
| 223 | sub error | ||
| 224 | { | ||
| 225 | my($self, $strErro) = @_; | ||
| 226 | my %resposta = ( | ||
| 227 | status => "error", | ||
| 228 | response => $strErro, | ||
| 229 | ); | ||
| 230 | my $json = \%resposta; | ||
| 231 | print to_json($json, { utf8 => 1 }); | ||
| 232 | exit; | ||
| 233 | } | ||
| 234 | |||
| 235 | =head2 Post | ||
| 236 | |||
| 237 | my $value_from_post = $core->Post($inputname); | ||
| 238 | |||
| 239 | Retrieve data from POST method | ||
| 240 | |||
| 241 | |||
| 242 | =cut | ||
| 243 | sub Post() | ||
| 244 | { | ||
| 245 | my($self, $item) = @_; | ||
| 246 | if($framework eq "ASP") | ||
| 247 | { | ||
| 248 | return $self->noInjection($request->Form($item)->Item()); | ||
| 249 | } | ||
| 250 | elsif($framework eq "CGI") | ||
| 251 | { | ||
| 252 | return $self->noInjection($cgi->param($item)); | ||
| 253 | } | ||
| 254 | else | ||
| 255 | { | ||
| 256 | return "defina framework"; | ||
| 257 | } | ||
| 258 | } | ||
| 259 | |||
| 260 | =head2 GET | ||
| 261 | |||
| 262 | my $value_from_get = $core->Get($inputname); | ||
| 263 | |||
| 264 | Retrieve data from GET method | ||
| 265 | |||
| 266 | |||
| 267 | =cut | ||
| 268 | sub Get() | ||
| 269 | { | ||
| 270 | my($self,$item) = @_; | ||
| 271 | if($framework eq "ASP") | ||
| 272 | { | ||
| 273 | return $self->noInjection($request->QueryString($item)->Item()); | ||
| 274 | } | ||
| 275 | elsif($framework eq "CGI") | ||
| 276 | { | ||
| 277 | return $self->noInjection($cgi->url_param($item)); | ||
| 278 | } | ||
| 279 | else | ||
| 280 | { | ||
| 281 | return "framework undefined"; | ||
| 282 | } | ||
| 283 | |||
| 284 | } | ||
| 285 | |||
| 286 | =head2 getpath | ||
| 287 | |||
| 288 | my $abs_path = $core->getpath($vpath_string); | ||
| 289 | |||
| 290 | Return absolute path of a given virtual / alias path | ||
| 291 | |||
| 292 | |||
| 293 | =cut | ||
| 294 | sub getpath() | ||
| 295 | { | ||
| 296 | my($self, $vpath) = @_; | ||
| 297 | return $server->MapPath($vpath) | ||
| 298 | } | ||
| 299 | |||
| 300 | =head2 getdomain | ||
| 301 | |||
| 302 | my $domain = $core->getdomain(); | ||
| 303 | |||
| 304 | Return the domain application | ||
| 305 | |||
| 306 | |||
| 307 | =cut | ||
| 308 | sub getdomain() | ||
| 309 | { | ||
| 310 | my($self) = @_; | ||
| 311 | return $request->ServerVariables("server_name"); | ||
| 312 | } | ||
| 313 | |||
| 314 | =head2 framework | ||
| 315 | |||
| 316 | my $framework_factory = $core->framework(); | ||
| 317 | |||
| 318 | Return the framework factory in use | ||
| 319 | |||
| 320 | |||
| 321 | =cut | ||
| 322 | sub framework() | ||
| 323 | { | ||
| 324 | my( $self ) = @_; | ||
| 325 | return $framework; | ||
| 326 | } | ||
| 327 | |||
| 328 | =head1 AUTHOR | ||
| 329 | |||
| 330 | José Eduardo Perotta de Almeida, C<< eduardo at web2solutions.com.br >> | ||
| 331 | |||
| 332 | |||
| 333 | =head1 LICENSE AND COPYRIGHT | ||
| 334 | |||
| 335 | Copyright 2012 José Eduardo Perotta de Almeida. | ||
| 336 | |||
| 337 | This program is free software; you can redistribute it and/or modify it | ||
| 338 | under the terms of either: the GNU General Public License as published | ||
| 339 | by the Free Software Foundation; or the Artistic License. | ||
| 340 | |||
| 341 | See http://dev.perl.org/licenses/ for more information. | ||
| 342 | |||
| 343 | |||
| 344 | =head1 BUGS AND LIMITATIONS | ||
| 345 | |||
| 346 | No bugs have been reported. | ||
| 347 | |||
| 348 | Please report any bugs or feature requests through the web interface at | ||
| 349 | L<http://rt.cpan.org>. | ||
| 350 | |||
| 351 | =head1 DISCLAIMER OF WARRANTY | ||
| 352 | |||
| 353 | BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | ||
| 354 | FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT | ||
| 355 | WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER | ||
| 356 | PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, | ||
| 357 | EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 358 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 359 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE | ||
| 360 | SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME | ||
| 361 | THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. | ||
| 362 | |||
| 363 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||
| 364 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | ||
| 365 | REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE | ||
| 366 | TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR | ||
| 367 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE | ||
| 368 | SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING | ||
| 369 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A | ||
| 370 | FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF | ||
| 371 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH | ||
| 372 | DAMAGES. | ||
| 373 | |||
| 374 | =cut | ||
| 375 | 1; |